[Solution] Fixed Point Guessing Codeforces Solution
This is an interactive problem.
Initially, there is an array , where is an odd positive integer. The jury has selected disjoint pairs of elements, and then the elements in those pairs are swapped. For example, if , and the pairs and are swapped, then the resulting array is .
As a result of these swaps, exactly one element will not change position. You need to find this element.
To do this, you can ask several queries. In each query, you can pick two integers and (). In return, you will be given the elements of the subarray sorted in increasing order.
Find the element which did not change position. You can make at most queries.
The array is fixed before the interaction and does not change after your queries.
Recall that an array is a subarray of the array if can be obtained from by deletion of several
(possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
Each test contains multiple test cases. The first line contains an integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer (; is odd) — the length of the array .
After reading the first line of each test case, you should begin the interaction.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, begin the interaction by reading the integer .
To make a query, output "" () without quotes. Afterwards, you should read in integers — the integers , in increasing order. You can make at most such queries in a single test case.
If you receive the integer instead of an answer or the integer , it means your program has made an invalid query, has exceed the limit of queries, or has given incorrect answer on the previous test case. Your program must terminate immediately to receive a Wrong Answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
When you are ready to give the final answer, output "" () without quotes — the element that did not change position. Giving this answer does not count towards the limit of queries. Afterwards, your program must continue to solve the remaining test cases, or exit if all test cases have been solved.
After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see documentation for other languages.
Hacks
To make a hack, use the following format. The first line must contain an integer () — the number of test cases. The description of the test cases follows.
The first line of each test case must contain an integer (; is odd) — the length of the array .
The second line of each test case must contain space-separated integers () — the elements of . The array should be the result of disjoint swaps on the array .
No comments:
Post a Comment