Codeforces Round 1087 (Div. 2)
C
Find the Zero
Codeforces
1400
原题
← BD →
翻译中…

This is an interactive problem.

翻译中…

You are given an integer $n$. There is a hidden array $a$ of length $2n$. Each integer from $1$ to $n$ appears exactly once in $a$. The rest of the elements are all $0$.

翻译中…

You can make the following type of query:

翻译中…
  • Choose two integers $i$ and $j$ ($1 \le i,j \le 2n$, $i \ne j$). The judge will respond with $1$ if $a_i=a_j$, and will respond with $0$ otherwise.
翻译中…

Find any integer $k$ ($1 \le k \le 2n$) such that $a_k=0$ in no more than $n+1$ queries. Note that the interactor is adaptive, which means that the hidden array $a$ may change depending on your queries but will not contradict previous queries.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^3$). The description of the test cases follows.

翻译中…

The first line of each test case contains an integer $n$ ($2 \le n \le 10^4$). The length of the hidden array $a$ will be $2n$.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^4$.

翻译中…

Interaction

翻译中…

To make a query, output a line in the following format:

翻译中…
  • $\texttt{?}\;i\;j$ ($1 \le i,j \le 2n$, $i \ne j$)
翻译中…

As a response to the query, you will get:

翻译中…
  • $1$ if $a_i=a_j$;
  • $0$ if $a_i \ne a_j$;
  • $-1$ if you made an invalid query or if you exceed the limit of $n+1$ queries.
翻译中…

To report the answer, output a line in the following format:

翻译中…
  • $\texttt{!}\;k$ ($1 \le k \le 2n$)
翻译中…

After this, proceed to the next test case or terminate if this is the last test case.

翻译中…

Note that reporting the answer does not count towards the $n+1$ queries.

翻译中…

The interactor is adaptive. This means that the hidden array $a$ may change depending on your queries but will not contradict previous queries.

翻译中…

After printing each query do not forget to output the end of line and flush$^{\text{∗}}$ the output. Otherwise, you will get Idleness limit exceeded verdict. If, at any interaction step, you read $-1$ instead of valid data, your solution must exit immediately. This means that your solution will receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.

翻译中…

For this problem, hacks are disabled.

翻译中…

$^{\text{∗}}$To flush, use: fflush(stdout) or cout.flush() in C++; sys.stdout.flush() in Python; see the documentation for other languages.

翻译中…

Note

翻译中…

In the first example test case, the hidden array $a$ is $[0,1,0,2]$:

翻译中…
  • In the first query, $(i,j)=(1,2)$. Since $a_1=0$, $a_2=1$, $a_1 \ne a_2$, the judge responds with $0$.
  • In the second query, $(i,j)=(3,1)$. Since $a_3=0$, $a_1=0$, $a_3 = a_1$, the judge responds with $1$.
  • The program reports $k=3$ as an answer. Since $a_3=0$, the answer is correct.
翻译中…

In the second example test case, the hidden array $a$ is $[3,2,0,1,0,0]$:

翻译中…
  • In the first query, $(i,j)=(5,6)$. Since $a_5=0$, $a_6=0$, $a_5 = a_6$, the judge responds with $1$.
  • In the second query, $(i,j)=(2,4)$. Since $a_2=2$, $a_4=1$, $a_2 \ne a_4$, the judge responds with $0$.
  • In the third query, $(i,j)=(1,3)$. Since $a_1=3$, $a_3=0$, $a_1 \ne a_3$, the judge responds with $0$.
  • The program reports $k=6$ as an answer. Since $a_6=0$, the answer is correct.
翻译中…

样例

Input #1
2
2

0

1

3

1

0

0
Output #1
? 1 2

? 3 1

! 3

? 5 6

? 2 4

? 1 3

! 6
InputCopy OutputCopy
题目信息
题号
2209C
时间限制
2 s
内存限制
256 MB
标签
构造
交互题

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