Codeforces Round 1053 (Div. 2)
G2
Hidden Single (Version 2)
Codeforces
未评级
原题
← G1→
翻译中…

The two versions have different constraints on $t$, $n$, and the maximum number of queries, and solving one of the two versions does not necessarily solve the other. You may want to read both versions. Hacks are disabled in both versions.

翻译中…

This is an interactive problem.

翻译中…

There is a hidden array $a_1, a_2, \ldots, a_{2n-1}$ containing all the numbers from $1$ to $n$, and all of them appear twice except one (which only appears once).

翻译中…

You can ask queries in the following format, where $S$ is a subset of $\{1, 2, \ldots, 2n-1\}$ and $x$ is an integer in $[1, n]$:

翻译中…
  • $\texttt{ask(S, x)}$: does there exist $i \in S$ such that $a_i = x$?
翻译中…

Find the number appearing exactly once, using at most $925$ queries. You don't need to find its position.

翻译中…

Note that the interactor is not adaptive, which means that the hidden array does not depend on the queries you make.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains a single integer $n$ ($n = 300$) — the maximum value in the hidden array $a_1, a_2, \ldots, a_{2n-1}$.

翻译中…

There are exactly $50$ tests in this problem (including the example). The example has $t = 1$, and all the other tests have $t = 20$.

翻译中…

Interaction

翻译中…

For each test case, first read a single integer $n$. If the integer you read is $-1$, it means that the answer to the previous test case was wrong, and you should exit immediately.

翻译中…

You may ask up to $925$ queries in each test case.

翻译中…

To ask a query, print a line in the format $\texttt{? x |S| S_1 S_2 ... S_|S|}$ with $1 \leq x \leq n$, $1 \leq S_1, S_2, \ldots, S_{|S|} \leq 2n-1$, and all the $S_i$ distinct.

翻译中…

As a response to the query, you will get $1$ if the answer is yes, $0$ if the answer is no, and $-1$ if you made an invalid query. You should exit immediately if you receive a $-1$.

翻译中…

To output an answer, you should print $\texttt{! y}$, where $y$ is the number that appears exactly once. Printing the answer doesn't count as a query.

翻译中…

See the interaction example for more clarity.

翻译中…

If you ask too many queries, you ask a malformed query, or your answer is wrong, you will get $\texttt{Wrong answer}$.

翻译中…

After printing a query, do not forget to output the end of line and flush the output. Otherwise, you will get $\texttt{Idleness limit exceeded}$. To do this, use:

翻译中…
  • $\texttt{fflush(stdout)}$ or $\texttt{cout.flush()}$ in C++;
  • $\texttt{System.out.flush()}$ in Java;
  • $\texttt{flush(output)}$ in Pascal;
  • $\texttt{stdout.flush()}$ in Python;
  • see the documentation for other languages.
翻译中…

Note that the interactor is not adaptive, which means that the hidden arrays do not depend on the queries you make.

翻译中…

Note

翻译中…

In the first test case, $n = 300$, so the hidden array has length $2n-1 = 599$.

翻译中…

#Contestant printsInteractor repliesExplanation1? 187 1 10Query: does $a_1=187$? No.2! 187We feel lucky, and claim that the answer is $187$. Fortunately, the answer is correct.

翻译中…

We have asked $1$ query (printing the answer does not count as a query), which is less than the maximum allowed number of queries ($925$).

翻译中…

样例

Input #1
1
300

0
Output #1
? 187 1 1

! 187
InputCopy OutputCopy
题目信息
题号
2151G2
时间限制
5 s
内存限制
256 MB

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