#P12531. [XJTUPC 2025] Beat Verdict: Precision Strike

    ID: 12364 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>二分2025交互题Special JudgeO2优化高校校赛

[XJTUPC 2025] Beat Verdict: Precision Strike

Description

This is an interactive problem.

You are playing a music game. In expert mode, you need to accurately calibrate the timing parameter for hitting notes, which is a mysterious integer\textbf{integer} xx within the range [1,n][1,n].

To determine this parameter, you can perform at most 44 calibration tests. In each test, you choose an integer\textbf{integer} test value yy (1yn1 \le y \le n), and the system will inform you whether y>xy > x is true or not. Ultimately, you need to provide an integer\textbf{integer} estimated parameter value xx' (1xn1 \le x' \le n), such that x[0.5x,2x]x' \in \left[0.5x, 2x\right].

Note: The final estimated value xx' does not count towards the aforementioned maximum of 44 tests.

Input Format

The input contains multiple test cases. The first line of the data contains an integer tt (1t5001\le t\le 500) indicating the number of test cases. The interaction process for each test case is described below.

In each test case, the first line of input contains a positive integer nn (1n5×1091\le n \le 5 \times 10^9), representing the possible range of the parameter.

If you want to perform a calibration test, output ? y\tt{?\ y} (1yn1 \le y \le n). Then you will read the response to that test, which will be an integer aa (a{0,1}a \in \{0, 1\}), where 1\tt{1} indicates that y>xy>x is true, and 0\tt{0} indicates that y>xy>x is false.

If you want to submit the calibration parameter xx', output ! x\tt{!\ x'} (1xn1 \le x' \le n). You will then immediately end the interaction for this test case and prepare for the interaction of the next test case. This interaction does not count towards the maximum of 44 tests.

Note that at the end of each round of output in your program (i.e., after each output of ? y\tt{?\ y} or ! x\tt{!\ x'}), $\textbf{you need to output a newline and flush the output buffer}$; otherwise, you will receive Time Limit Exceeded\tt{Time\ Limit\ Exceeded}.

You can use:

  • C's fflush(stdout)\tt{fflush(stdout)};
  • C++'s cout.flush()\tt{cout.flush()};
  • Java's System.out.flush()\tt{System.out.flush()};
  • Python's stdout.flush()\tt{stdout.flush()};

to flush the output buffer.

Please note: The interactive library is adaptive, meaning that the positive integer xx (1xn1 \le x \le n) may change with your inputs\textbf{may change with your inputs} in each test case, but it will always satisfy all previously made inquiries.

If the answer you output at the end is correct, you will receive Accepted\tt{Accepted};

If your inquiries do not conform to the problem's range requirements, or if the final answer you output is incorrect, you will receive WrongAnswer\tt{Wrong Answer};

Additionally, other evaluation results will still be returned during the evaluation process based on normal circumstances.

Output Format

See also interactive format.

2
1

8

1

1

0

0




! 1

? 6

? 4

? 2

? 3

! 3

Hint

In the first test case, it can be uniquely determined that x=1x = 1, so we directly submit x=1x' = 1.

In the second test case, the hidden parameter x=3x = 3, and the interaction process is as follows:

  • Test y=6y=6, the response is that y>xy>x is true;
  • Test y=4y=4, the response is that y>xy>x is true;
  • Test y=2y=2, the response is that y>xy>x is false;
  • Test y=3y=3, the response is that y>xy>x is false;
  • Submit x=3x' = 3.

Please note that this example only serves to demonstrate the interaction format. It is not guaranteed that the queries provided are optimal or uniquely determine the answer.