Codeforces Round 723 (Div. 2)
F
Median Queries
Codeforces
3000
原题
← E→
翻译中…

This is an interactive problem.

翻译中…

There is a secret permutation $p$ ($1$-indexed) of numbers from $1$ to $n$. More formally, for $1 \leq i \leq n$, $1 \leq p[i] \leq n$ and for $1 \leq i \lt j \leq n$, $p[i] \neq p[j]$. It is known that $p[1] \lt p[2]$.

翻译中…

In $1$ query, you give $3$ distinct integers $a,b,c$ ($1 \leq a,b,c \leq n$), and receive the median of $\{|p[a]-p[b]|,|p[b]-p[c]|,|p[a]-p[c]|\}$.

翻译中…

In this case, the median is the $2$-nd element ($1$-indexed) of the sequence when sorted in non-decreasing order. The median of $\{4,6,2\}$ is $4$ and the median of $\{0,123,33\}$ is $33$.

翻译中…

Can you find the secret permutation in not more than $2n+420$ queries?

翻译中…

Note: the grader is not adaptive: the permutation is fixed before any queries are made.

翻译中…

Input

翻译中…

The first line of input contains a single integer $t$ $(1 \leq t \leq 1000)$ — the number of testcases.

翻译中…

The first line of each testcase consists of a single integer $n$ $(20 \leq n \leq 100000)$ — the length of the secret permutation.

翻译中…

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

翻译中…

Interaction

翻译中…

For each testcase, you begin the interaction by reading $n$.

翻译中…

To perform a query, output "? a b c" where $a,b,c$ is the $3$ indices you want to use for the query.

翻译中…

Numbers have to satisfy $1 \leq a,b,c \leq n$ and $a \neq b$,$b \neq c$,$a \neq c$.

翻译中…

For each query, you will receive a single integer $x$: the median of $\{|p[a]-p[b]|,|p[b]-p[c]|,|p[a]-p[c]|\}$.

翻译中…

In case your query is invalid or you asked more than $2n+420$ queries, the interactor will print "−1" and will finish interaction. You will receive Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.

翻译中…

When you have determined the secret permutation, output "! p[1] p[2] ... p[n]". If the secret permutation is correct, the interactor will print "1". Otherwise, the interactor will print "-1" and will finish interaction. You will receive Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.

翻译中…

After printing a query do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded verdict.

翻译中…

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 of test:

翻译中…

The first line should contain a single integer $t$ ($1 \leq t \leq 1000$) — the number of testcases.

翻译中…

The first line of each testcase should contain a single integer $n$ ($20 \leq n \leq 100000$) — the length of the secret permutation.

翻译中…

The following line of should contain $n$ integers $p[1],p[2],p[3],\ldots,p[n]$. $p[1] \lt p[2]$ and $p$ must be a permutation of integers from $1$ to $n$.

翻译中…

You must ensure that the sum of $n$ over all testcases does not exceed $100000$.

翻译中…

Note

翻译中…

The secret permutation is $\{9,10,19,7,16,18,11,14,15,6,20,8,17,4,5,3,12,2,13,1\}$.

翻译中…

For the first query, the values of $(a,b,c)$ is $(1,5,2)$. Since $p[1]=9$, $p[5]=16$ and $p[2]=10$. The return value is the median of $\{|9-16|,|16-10|,|9-10|\}$ which is $6$.

翻译中…

For the second query, the values of $(a,b,c)$ is $(20,19,2)$. Since $p[20]=1$, $p[19]=13$ and $p[2]=10$. The return value is the median of $\{|1-13|,|13-10|,|1-10|\}$ which is $9$.

翻译中…

By some miracle, we have figured out that the secret permutation is $\{9,10,19,7,16,18,11,14,15,6,20,8,17,4,5,3,12,2,13,1\}$. We output it and receive $1$ from the interactor, meaning that we have guessed the secret permutation correctly.

翻译中…

样例

Input #1
1
20

6

9

1
Output #1
? 1 5 2

? 20 19 2

! 9 10 19 7 16 18 11 14 15 6 20 8 17 4 5 3 12 2 13 1
InputCopy OutputCopy
题目信息
题号
1526F
时间限制
6 s
内存限制
256 MB
标签
构造
交互题
概率论

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