Codeforces Round 1085 (Div. 1 + Div. 2)
H2
Bowser's Castle (Medium Version)
Codeforces
3500
原题
← H1H3 →
翻译中…

image

翻译中…

This is the medium version of the problem. The difference between the versions is that in this version, $n \leq 200$ and you may make $10^4$ queries. You can hack only if you solved all versions of this problem.

翻译中…

This is an interactive problem.

翻译中…

Let $n$ be a positive integer. A function on $n$ variables $x_1, \ldots, x_n$ is called min-max if it can be constructed as writing only $\min$ and $\max$ calls around $x_1, \ldots, x_n$ with each variable appearing exactly once in order from left to right in the expression. For example, $\min(x_1, x_2, x_3)$ is a min-max function on $3$ variables, but $\max(\min(x_1, x_3), x_2)$ and $\min(\max(x_1, x_2), \max(x_2, x_3))$ are not.

翻译中…

Bowser has chosen a min-max function on $n$ ($2 \leq n \leq 200$) variables and tells you $n$. Additionally, he lets you ask queries of the following form: you give Bowser $n$ integers $x_1, \ldots, x_n$ ($1 \leq x_i \leq 10^9$) as input, and he tells you $f(x_1, \ldots, x_n)$.

翻译中…

To escape his castle, you have to deduce his function using at most $10^4$ queries in total. After that, to prove to him that you have learned the function, Bowser will give you up to $5000$ of his own inputs $x_1, \ldots, x_n$, to which you must respond with the correct value of $f(x_1, \ldots, x_n)$.

翻译中…

Since Bowser's castle is very secure, he actually has multiple functions for you to figure out, with a total variable count of at most $200$. Additionally, he constrains that you use at most $10^4$ queries across all of the functions and that he will also not ask more than $5000$ queries in total.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains a single integer $n$ ($2 \leq n \leq 200$) — the number of variables in the min-max function.

翻译中…

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

翻译中…

After you read this line of input, the interaction begins with your first query.

翻译中…

Interaction

翻译中…

To make a query, output a line (without quotes) in the following format:

翻译中…
  • "? $x_1$ $x_2$ $\ldots$ $x_n$" ($1 \leq x_i \leq 10^9$).
翻译中…

Then, after each query, read a single integer — the answer to your query. You can make up to $10^4$ queries of this type in total across all $t$ test cases.

翻译中…

Once you are ready to begin answering Bowser's queries, output a line containing a single character "!" (without quotes).

翻译中…

Each of Bowser's queries contains a single line of $n$ integers $x_1, x_2, \ldots, x_n$ ($1 \leq x_i \leq 10^9$) — Bowser's input. It is guaranteed that Bowser will not make more than $5000$ queries in total across all $t$ test cases.

翻译中…

After each query, output a single integer — the value of $f(x_1, x_2, \ldots, x_n)$. Note that these queries are online, so Bowser will only provide you the next query after you respond to his previous query.

翻译中…

Once Bowser is done asking queries, you will receive a single line containing the integer $0$. After this, proceed to the next test case or exit if this is the last test case.

翻译中…

The interactor in this task is partially adaptive. In particular, the functions Bowser chooses are fixed at the beginning of each interaction, but his queries to you may change.

翻译中…

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 reveive 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 hack, use the following format.

翻译中…

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

翻译中…

The first line of each test case should contain a single integer $n$ ($2 \leq n \leq 200$) — the number of variables in the min-max function.

翻译中…

The second line of each test case should contain a series of space-separated tokens (without quotes) from the following list, specifying the min-max function:

翻译中…
  • "min"
  • "max"
  • "("
  • ")"
  • ","
  • positive integers in the range $1, 2, \ldots, n$.
翻译中…

The sum of $n$ over all test cases should not exceed $200$.

翻译中…

For instance, the hack case corresponding to the example input is as follows:

翻译中…

2
3
max ( 1 , 2 , 3 )
4
min ( max ( 1 , 2 ) , max ( 3 , 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, Bowser's min-max function is $f := \max(x_1, x_2, x_3)$. After asking two queries to receive $f(5, 4, 3) = 5$ and $f(1, 2, 1) = 2$ from the jury, the solution is ready to answer the jury's queries. It correctly deduces that $f(3, 6, 2) = 6$ and $f(3, 5, 7) = 7$.

翻译中…

In the second test case, Bowser's min-max function is $f := \min(\max(x_1, x_2), \max(x_3, x_4))$. After asking two queries to receive $f(1, 9, 8, 7) = 8$ and $f(5, 10^9, 2, 3) = 3$ from the jury, the solution is ready to answer the jury's queries. It correctly deduces that $f(8, 7, 6, 5) = 6$.

翻译中…

Note that it is not guaranteed that the queries in the example uniquely determine the min-max function. The example is there only to demonstrate how the queries work. Empty lines in the example input and output are given only for better readability; you don't need to output them in your solution.

翻译中…

样例

Input #1
2
3

5

2

3 6 2

3 5 7

0
4

8

3

8 7 6 5

0
Output #1
? 5 4 3

? 1 2 1

!

6

7

? 1 9 8 7

? 5 1000000000 2 3

!

6
InputCopy OutputCopy
题目信息
题号
2207H2
时间限制
8 s
内存限制
256 MB
标签
构造
分治
交互题
树
双指针

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