Codeforces Round 987 (Div. 2)
F
Penchick and Even Medians
Codeforces
2800
原题
← E→
翻译中…

This is an interactive problem.

翻译中…

Returning from a restful vacation on Australia's Gold Coast, Penchick forgot to bring home gifts for his pet duck Duong Canh! But perhaps a beautiful problem crafted through deep thought on the scenic beaches could be the perfect souvenir.

翻译中…

There is a hidden permutation$^{\text{∗}}$ $p$ of length $n$, where $n$ is even. You are allowed to make the following query:

翻译中…
  • Choose a subsequence$^{\text{†}}$ of the permutation $p$ with even length $4\le k\le n$. The interactor will return the value of the two medians$^{\text{‡}}$ in the chosen subsequence.
翻译中…

Find the index of the two medians in permutation $p$ using at most $80$ queries.

翻译中…

Note that the interactor is non-adaptive. This means that the permutation $p$ is fixed at the beginning and will not change based on your queries.

翻译中…

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array). $^{\text{†}}$A sequence $a$ is a subsequence of a sequence $b$ if $a$ can be obtained from $b$ by the deletion of several (possibly, zero or all) element from arbitrary positions. $^{\text{‡}}$The two medians of an array $a$ with even length $k$ are defined as the $\frac{k}{2}$-th and $\left(\frac{k}{2} + 1\right)$-th smallest element in the array ($1$-indexed).

翻译中…

Input

翻译中…

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

翻译中…

The only line of each test case contains a single integer $n$ ($6 \le n \le 100$, $n$ is even) — the length of the hidden permutation $p$.

翻译中…

For each test case, after reading the integer $n$, you should begin the interaction and find the answer before reading $n$ for the next test case.

翻译中…

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

翻译中…

Interaction

翻译中…

To make a query, print a single line in the following format:

翻译中…
  • $\mathtt{?}\;k\;x_1\;x_2 \ldots x_{k-1}\;x_k$ ($4\le k\le n$, $k$ is even, $1 \le x_i \le n$, $x_i$ is pairwise distinct) — the length of the chosen subsequence followed by the indices of the chosen subsequence.
翻译中…

After each query, you should read a line containing two integers $m_1$ and $m_2$ ($1 \le m_1 \lt m_2 \le n$) — the value of the two medians in array $[p_{x_1}, p_{x_2}, \ldots, p_{x_{k-1}}, p_{x_k}]$.

翻译中…

You can make at most $80$ such queries in each test case.

翻译中…

To give the final answer, print a single line in the following format:

翻译中…
  • $\mathtt{!}\;i_1\;i_2$ ($1\le i_1, i_2 \le n$) — the index of the two medians.
翻译中…

Note that the order in which $i_1$ and $i_2$ is printed does not matter. In other words, your solution is valid as long as $p_{i_1} = \frac{n}{2}$ and $p_{i_2} = \frac{n}{2} + 1$, or $p_{i_1} = \frac{n}{2} + 1$ and $p_{i_2} = \frac{n}{2}$.

翻译中…

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.

翻译中…

Hack format

翻译中…

For hacks, use the following format.

翻译中…

The first line should contain $t$ — the number of test cases.

翻译中…

The first line of each test case should contain a single even integer $n$.

翻译中…

The second line of each test case should contain a permutation $p_1, p_2, \ldots, p_n$ of length $n$.

翻译中…

As an example, the hack format for the example input is:

翻译中…

2
6
6 2 3 5 1 4
10
10 9 8 7 6 5 4 3 2 1

翻译中…

$^{\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 test case, the hidden permutation is $p = [6, 2, 3, 5, 1, 4]$.

翻译中…
  1. The entire permutation was chosen for the first query. The two medians of the entire permutation $p$ are $3$ and $4$.
  2. The indices of the chosen subsequence in the second query are $3$, $6$, $1$, and $5$. The interactor returns the two medians of the subsequence $[p_3, p_6, p_1, p_5] = [3, 4, 6, 1]$, which are $3$ and $4$.
  3. The indices of the chosen subsequence in the second query are $3$, $6$, $2$, and $5$. The interactor returns the two medians of the subsequence $[p_3, p_6, p_2, p_5] = [3, 4, 2, 1]$, which are $2$ and $3$.
翻译中…

The answer "! 3 6" is valid as $p_3 = 3$ and $p_6 = 4$.

翻译中…

In the second test case, the hidden permutation is $p = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]$.

翻译中…
  1. The indices of the chosen subsequence in the second query are $1$, $3$, $7$, $8$, $9$, and $10$. The interactor returns the two medians of the subsequence $[p_1, p_3, p_7, p_8, p_9, p_{10}] = [10, 8, 4, 3, 2, 1]$, which are $3$ and $4$.
  2. The indices of the chosen subsequence in the second query are $1$, $2$, $3$, $4$, $5$, $6$, $7$, and $8$. The interactor returns the two medians of the subsequence $[p_1, p_2, p_3, p_4, p_5, p_6, p_7, p_8] = [10, 9, 8, 7, 6, 5, 4, 3]$, which are $6$ and $7$.
翻译中…

The answer "! 5 6" is valid as $p_5 = 6$ and $p_6 = 5$.

翻译中…

样例

Input #1
2
6

3 4

3 4

2 3

10

3 4

6 7
Output #1
? 6 1 2 3 4 5 6

? 4 3 6 1 5

? 4 3 6 2 5

! 3 6

? 6 1 3 7 8 9 10

? 8 1 2 3 4 5 6 7 8

! 6 5
InputCopy OutputCopy
题目信息
题号
2031F
时间限制
3 s
内存限制
256 MB
标签
二分
构造
交互题
概率论

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