Atto Round 1 (Codeforces Round 1041, Div. 1 + Div. 2)
G2
Inter Active (Hard Version)
Codeforces
3500
原题
← G1H →
翻译中…

This is the hard version of the problem. The difference between the versions is that in this version, you can make at most $10\cdot n$ queries. You can hack only if you solved all versions of this problem.

翻译中…

Ali loved Bahamin's gift (from problem E) so much that he illegally traveled from Qazvin to Liverpool to have the gift signed by football players. Now Interpol is searching for him, but they've offered a deal: solve a problem, and he can stay in Liverpool. But since he's currently at the stadium, he can't solve it — so he asked you to do it.

翻译中…

This is an interactive problem.

翻译中…

There is a hidden permutation$^{\text{∗}}$ $p$ of length $n\ge 4$, where $p_i \neq i$ for each $1 \leq i \leq n$.

翻译中…

Initially, you should give the jury a positive integer $k\le n$, which will be constant through future queries. Then you need to find permutation $p$ using some queries.

翻译中…

In each query, you give a permutation $q_1, q_2, \ldots, q_n$ to the jury. In response, you will receive the number of pairs $(i, j)$ such that all of the following conditions hold:

翻译中…
  • $i \lt j$;
  • $p_{q_i} = q_j$;
  • $i \neq k$. ($k$ is the constant you have given to the jury)
翻译中…

You are given $n$, and you need to find the permutation $p$ in at most $10\cdot n$ 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).

翻译中…

Input

翻译中…

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

翻译中…

The only line of each test case contains a single integer $n$ ($4 \leq n \leq 100$) — the length of $p$.

翻译中…

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

翻译中…

Interaction

翻译中…

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

翻译中…

Then you should output the integer $k$ ($1 \leq k \leq n$). This is not considered as a query.

翻译中…

Then you can ask up to $10\cdot n$ queries.

翻译中…

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

翻译中…
  • $\texttt{?}\,q_1\,q_2\,\ldots\,q_n$
翻译中…

The jury will return the answer to the query.

翻译中…

When you find the permutation $p$, output a single line in the following format:

翻译中…
  • $\texttt{!}\,p_1\,p_2\,\ldots\,p_n$
翻译中…

This is also not considered as a query.

翻译中…

After that, proceed to process the next test case or terminate the program if it is the last test case.

翻译中…

The interactor is not adaptive, which means that the permutation is determined before the participant outputs $k$.

翻译中…

If your program makes more than $10\cdot n$ queries, your program should immediately terminate to receive the verdict Wrong answer. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.

翻译中…

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.

翻译中…

Hacks

翻译中…

To perform a hack, use the following format:

翻译中…

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

翻译中…

The first line of each test case contains a single integer $n$ ($4 \leq n \leq 100$) — the length of $p$.

翻译中…

The second line contains $n$ integers $p_1, p_2, \ldots, p_n$ ($1 \le p_i \le n$, $p_i\ne i$, all $p_i$-s are distinct) — the permutation $p$.

翻译中…

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

翻译中…

$^{\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, $p = [3, 1, 4, 2]$. The solution selected $k=1$, then it asked permutation $q = [1, 2, 3, 4]$. Only pair $(3,4)$ satisfies the conditions.

翻译中…

In the second test case, $p = [3, 1, 2, 5, 4]$. The solution selected $k=3$.

翻译中…
  • For permutation $q = [1, 2, 5, 4, 3]$, only pair $(1, 5)$ satisfies the conditions.
  • For permutation $q = [2, 1, 4, 3, 5]$, pairs $(1, 2)$ and $(2, 4)$ satisfy the conditions.
翻译中…

样例

Input #1
2
4

1

5

1

2
Output #1
1
? 1 2 3 4

! 3 1 4 2

3
? 1 2 5 4 3

? 2 1 4 3 5

! 3 1 2 5 4
InputCopy OutputCopy
题目信息
题号
2127G2
时间限制
2 s
内存限制
512 MB
标签
二分
位运算
构造
图论
模拟
交互题
数学
概率论

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