310993: CF1918E. ace5 and Task Order

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. ace5 and Task Ordertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

This is an interactive problem!

In the new round, there were $n$ tasks with difficulties from $1$ to $n$. The coordinator, who decided to have the first round with tasks in unsorted order of difficulty, rearranged the tasks, resulting in a permutation of difficulties from $1$ to $n$. After that, the coordinator challenged ace5 to guess the permutation in the following way.

Initially, the coordinator chooses a number $x$ from $1$ to $n$.

ace5 can make queries of the form: $?\ i$. The answer will be:

  • $>$, if $a_i > x$, after which $x$ increases by $1$.
  • $<$, if $a_i < x$, after which $x$ decreases by $1$.
  • $=$, if $a_i = x$, after which $x$ remains unchanged.

The task for ace5 is to guess the permutation in no more than $40n$ queries. Since ace5 is too busy writing the announcement, he has entrusted this task to you.

Input

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

Interaction

The interaction between your program and the jury's program begins with reading a positive integer $n$ ($1 \leq n \leq 2000$) — the length of the hidden permutation.

To make a query, output a line in the format "? i", where $1 \leq i \leq n$.

As an answer, you will receive:

  • ">", if $a_i$ > $x$, after which $x$ will increase by $1$.
  • "<", if $a_i$ < $x$, after which $x$ will decrease by $1$.
  • "=", if $a_i$ = $x$, after which $x$ will remain unchanged.

You can make no more than $40n$ queries. To output the answer, you need to print "! a_1 a_2 ... a_n", where $1 \leq a_i \leq n$, and all of them are distinct. Outputting the answer does not count as a query.

If your program makes more than $40n$ queries for one test case, or makes an invalid query, then the response to the query will be -1. After receiving such a response, your program should immediately terminate to receive the verdict Wrong Answer. Otherwise, it may receive any other verdict.

After outputting a query, do not forget to print a newline and flush the output buffer. Otherwise, you will receive the verdict Presentation Error. To flush the buffer, use:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see the documentation for other languages.

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

The interactor in this problem is not adaptive.

Hacks:

To make a hack, use the following format:

The first line contains a single integer $t$ — the number of test cases.

The description of each test case should consist of two lines. The first line contains the numbers $n$ and $x$ ($1 \leq x \leq n \leq 2000$) — the length of the hidden permutation and the initial value of the number $x$. The second line contains $n$ distinct numbers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq n$) — the permutation that the jury should choose in this test case.

Sum of $n$ over all test cases should not exceed $2000$.

ExampleInput
2
5

>

=

<

=

<

<

2

>
Output
? 4

? 2

? 1

? 5

? 1

? 3

! 2 4 1 5 3

? 1

! 2 1 
Note

In the first test, the hidden permutation is $a$ = [$2,4,1,5,3$], and the initial value of $x$ is $3$.

In the second test, the hidden permutation is $a$ = [$2,1$], and the initial value of $x$ is $1$.

Output

题目大意:
这是一个交互式问题。在新的一轮中,有 n 个任务,难度从 1 到 n。协调员决定以难度未排序的顺序进行第一轮任务,重新排列任务,得到 1 到 n 的一个排列。之后,协调员挑战 ace5 去猜测这个排列,方式如下:

最初,协调员从 1 到 n 中选择一个数字 x。
ace5 可以提出如下形式的查询:?i。回答将是:
>,如果 ai > x,之后 x 增加 1。
<,如果 ai < x,之后 x 减少 1。
=,如果 ai = x,之后 x 保持不变。
ace5 的任务是猜测排列,查询次数不超过 40n。由于 ace5 太忙于写公告,他把这个任务交给了你。

输入输出数据格式:
输入:
第一行包含一个整数 t(1 ≤ t ≤ 1000)——测试用例的数量。

交互:
与裁判程序的交互从读取一个正整数 n(1 ≤ n ≤ 2000)开始——隐藏排列的长度。
进行查询,以格式"? i"输出一行,其中 1 ≤ i ≤ n。
作为回答,你将收到:
">",如果 ai > x,之后 x 将增加 1。
"<",如果 ai < x,之后 x 将减少 1。
"=",如果 ai = x,之后 x 将保持不变。
你可以进行不超过 40n 次查询。输出答案时,需要打印 "! a_1 a_2 ... a_n",其中 1 ≤ a_i ≤ n,并且它们都是不同的。输出答案不计入查询次数。
如果你的程序对一个测试用例进行超过 40n 次查询,或者提出无效查询,那么查询的响应将是 -1。在收到这样的响应后,你的程序应立即终止以获得错误答案的判决。否则,可能会收到任何其他判决。
输出查询后,不要忘记打印换行并刷新输出缓冲区。否则,你将收到格式错误的判决。刷新缓冲区的方法取决于使用的编程语言。

保证所有测试用例的 n 之和不超过 2000。

这个问题的交互器不是自适应的。

hacks:
进行 hack 时,使用以下格式:
第一行包含一个整数 t ——测试用例的数量。
每个测试用例的描述应包含两行。第一行包含数字 n 和 x(1 ≤ x ≤ n ≤ 2000)——隐藏排列的长度和数字 x 的初始值。第二行包含 n 个不同的数字 a_1, a_2, ..., a_n(1 ≤ a_i ≤ n)——裁判应在此测试用例中选择的排列。
所有测试用例的 n 之和不应超过 2000。题目大意: 这是一个交互式问题。在新的一轮中,有 n 个任务,难度从 1 到 n。协调员决定以难度未排序的顺序进行第一轮任务,重新排列任务,得到 1 到 n 的一个排列。之后,协调员挑战 ace5 去猜测这个排列,方式如下: 最初,协调员从 1 到 n 中选择一个数字 x。 ace5 可以提出如下形式的查询:?i。回答将是: >,如果 ai > x,之后 x 增加 1。 <,如果 ai < x,之后 x 减少 1。 =,如果 ai = x,之后 x 保持不变。 ace5 的任务是猜测排列,查询次数不超过 40n。由于 ace5 太忙于写公告,他把这个任务交给了你。 输入输出数据格式: 输入: 第一行包含一个整数 t(1 ≤ t ≤ 1000)——测试用例的数量。 交互: 与裁判程序的交互从读取一个正整数 n(1 ≤ n ≤ 2000)开始——隐藏排列的长度。 进行查询,以格式"? i"输出一行,其中 1 ≤ i ≤ n。 作为回答,你将收到: ">",如果 ai > x,之后 x 将增加 1。 "<",如果 ai < x,之后 x 将减少 1。 "=",如果 ai = x,之后 x 将保持不变。 你可以进行不超过 40n 次查询。输出答案时,需要打印 "! a_1 a_2 ... a_n",其中 1 ≤ a_i ≤ n,并且它们都是不同的。输出答案不计入查询次数。 如果你的程序对一个测试用例进行超过 40n 次查询,或者提出无效查询,那么查询的响应将是 -1。在收到这样的响应后,你的程序应立即终止以获得错误答案的判决。否则,可能会收到任何其他判决。 输出查询后,不要忘记打印换行并刷新输出缓冲区。否则,你将收到格式错误的判决。刷新缓冲区的方法取决于使用的编程语言。 保证所有测试用例的 n 之和不超过 2000。 这个问题的交互器不是自适应的。 hacks: 进行 hack 时,使用以下格式: 第一行包含一个整数 t ——测试用例的数量。 每个测试用例的描述应包含两行。第一行包含数字 n 和 x(1 ≤ x ≤ n ≤ 2000)——隐藏排列的长度和数字 x 的初始值。第二行包含 n 个不同的数字 a_1, a_2, ..., a_n(1 ≤ a_i ≤ n)——裁判应在此测试用例中选择的排列。 所有测试用例的 n 之和不应超过 2000。

加入题单

上一题 下一题 算法标签: