CF1698D.Fixed Point Guessing

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is an interactive problem.

Initially, there is an array a=[1,2,,n]a = [1, 2, \ldots, n] , where nn is an odd positive integer. The jury has selected n12\frac{n-1}{2} disjoint pairs of elements, and then the elements in those pairs are swapped. For example, if a=[1,2,3,4,5]a=[1,2,3,4,5] , and the pairs 141 \leftrightarrow 4 and 353 \leftrightarrow 5 are swapped, then the resulting array is [4,2,5,1,3][4, 2, 5, 1, 3] .

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 ll and rr ( 1lrn1 \leq l \leq r \leq n ). In return, you will be given the elements of the subarray [al,al+1,,ar][a_l, a_{l + 1}, \dots, a_r] sorted in increasing order.

Find the element which did not change position. You can make at most 15\mathbf{15} queries.

The array aa is fixed before the interaction and does not change after your queries.

Recall that an array bb is a subarray of the array aa if bb can be obtained from aa 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 tt ( 1t5001 \leq t \leq 500 ) — the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer nn ( 3n<1043 \leq n < 10^4 ; nn is odd) — the length of the array aa .

After reading the first line of each test case, you should begin the interaction.

It is guaranteed that the sum of nn over all test cases does not exceed 10410^4 .

输出格式

For each test case, begin the interaction by reading the integer nn .

To make a query, output " ?  l  r\texttt{?}\;l\;r " ( 1lrn1 \leq l \leq r \leq n ) without quotes. Afterwards, you should read in rl+1r-l+1 integers — the integers al,al+1,,ara_l, a_{l + 1}, \dots, a_r , in increasing order. You can make at most 1515 such queries in a single test case.

If you receive the integer 1-1 instead of an answer or the integer nn , 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 " !  x\texttt{!}\;x " ( 1xn1 \leq x \leq n ) without quotes — the element that did not change position. Giving this answer does not count towards the limit of 1515 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 tt ( 1t5001 \leq t \leq 500 ) — the number of test cases. The description of the test cases follows.

The first line of each test case must contain an integer nn ( 3n<1043 \leq n < 10^4 ; nn is odd) — the length of the array aa .

The second line of each test case must contain nn space-separated integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ain1 \le a_i \le n ) — the elements of aa . The array aa should be the result of n12\frac{n-1}{2} disjoint swaps on the array [1,2,,n][1,2,\dots,n] .

输入输出样例

  • 输入#1

    2
    5
    
    1 2 4 5
    
    1 3 5
    
    3
    
    1

    输出#1

    ? 1 4
    
    ? 3 5
    
    ! 2
    
    ? 1 1
    
    ! 1

说明/提示

In the first test, the interaction proceeds as follows.

SolutionJuryExplanation 2\texttt{2} There are 2 test cases. 5\texttt{5} In the first test case, the hidden array is [4,2,5,1,3][4,2,5,1,3] , with length 55 . ? 1 4\texttt{? 1 4} 1 2 4 5\texttt{1 2 4 5} The solution requests the subarray [4,2,5,1][4,2,5,1] in increasing order, and the jury responds with [1,2,4,5][1,2,4,5] . ? 3 5\texttt{? 3 5} 1 3 5\texttt{1 3 5} The solution requests the subarray [5,1,3][5,1,3] in increasing order, and the jury responds with [1,3,5][1,3,5] . ! 2\texttt{! 2} The solution has somehow determined that a2=2a_2=2 , and outputs it. Since the output is correct, the jury continues to the next test case. 3\texttt{3} In the second test case, the hidden array is [1,3,2][1,3,2] , with length 33 . ? 1 1\texttt{? 1 1} 1\texttt{1} The solution requests the number [1][1] only, and the jury responds with [1][1] . ! 1\texttt{! 1} The solution has determined that a1=1a_1=1 , and outputs it. Since the output is correct and there are no more test cases, the jury and the solution exit.Note that the line breaks in the example input and output are for the sake of clarity, and do not occur in the real interaction.

首页