Codeforces Round 812 (Div. 2)
D
Tournament Countdown
Codeforces
1800
原题
← CE →
翻译中…

This is an interactive problem.

翻译中…

There was a tournament consisting of $2^n$ contestants. The $1$-st contestant competed with the $2$-nd, the $3$-rd competed with the $4$-th, and so on. After that, the winner of the first match competed with the winner of second match, etc. The tournament ended when there was only one contestant left, who was declared the winner of the tournament. Such a tournament scheme is known as the single-elimination tournament.

翻译中…

You don't know the results, but you want to find the winner of the tournament. In one query, you select two integers $a$ and $b$, which are the indices of two contestants. The jury will return $1$ if $a$ won more matches than $b$, $2$ if $b$ won more matches than $a$, or $0$ if their number of wins was equal.

翻译中…

Find the winner in no more than $\left \lceil \frac{1}{3} \cdot 2^{n + 1} \right \rceil$ queries. Here $\lceil x \rceil$ denotes the value of $x$ rounded up to the nearest integer.

翻译中…

Note that the tournament is long over, meaning that the results are fixed and do not depend on your queries.

翻译中…

Input

翻译中…

The first line contains a single integer $t$ ($1 \leq t \leq 2^{14}$) — the number of test cases.

翻译中…

The only line of input contains a single integer $n$ ($1 \leq n \leq 17$).

翻译中…

It is guaranteed that the sum of $2^n$ over all test cases does not exceed $2^{17}$.

翻译中…

Interaction

翻译中…

The interaction for each test case begins by reading the integer $n$.

翻译中…

To make a query, output "? a b" ($1 \leq a, b \leq 2^n$) without quotes. Afterwards, you should read one single integer — the answer for your query. You can make at most $\left \lceil \frac{1}{3} \cdot 2^{n + 1} \right \rceil$ such queries in each test case.

翻译中…

If you receive the integer $-1$ instead of an answer or a valid value of $n$, 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" ($1 \leq x \leq 2^n$) without quotes — the winner of the tournament. Giving this answer does not count towards the limit of queries. After solving a test case, your program should move to the next one immediately. After solving all test cases, your program should be terminated immediately.

翻译中…

After printing a query or the answer 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 hack, use the following format.

翻译中…

The first line contains an integer $t$ ($1 \leq t \leq 2^{14}$) — the number of test cases.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \leq n \leq 17$).

翻译中…

The second line of each test case contains $2^n$ numbers on a line — the number of wins of each participant. There should be a sequence of matches that is consistent with the number of wins.

翻译中…

The sum of $2^n$ should not exceed $2^{17}$.

翻译中…

Note

翻译中…

The tournament in the first test case is shown below. The number of wins is $[1,0,0,2,0,1,3,0]$.

翻译中…

image In this example, the winner is the $7$-th contestant.

翻译中…

样例

Input #1
1
3

2

0

2
Output #1
? 1 4

? 1 6

? 5 7

! 7
InputCopy OutputCopy
题目信息
题号
1713D
时间限制
2 s
内存限制
256 MB
标签
构造
贪心
交互题
数论
概率论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。