Codeforces Round 1045 (Div. 2)
E
Power Boxes
Codeforces
2300
原题
← DF →
翻译中…

This is an interactive problem.

翻译中…

You are given $n$ boxes, indexed from $1$ to $n$. The boxes look identical, but each one has a hidden power value $a_i$, which is either $1$ or $2$.

翻译中…

You want to determine the power value of each box. To do so, you conduct the following experiment. Initially, the $i$-th box is placed at coordinate $i$ on a number line ($1 \le i \le n$).

翻译中…

You are allowed to perform the following two types of queries:

翻译中…
  • "swap $x$" ($1 \le x \le n - 1$): Swap the boxes currently located at coordinates $x$ and $x + 1$. Note that this change is permanent and affects all subsequent queries.
  • "throw $x$" ($1 \le x \le n$): Throw a ball at the box located at coordinate $x$. The ball travels $p$ units forward to coordinate $x + p$ if the power value of the box is $p$. If there is a box at the new coordinate, the ball jumps again using the power of that box. This continues until the ball lands on a coordinate without a box. As a response, you are given the total number of jumps the ball made before stopping.
翻译中…

Your task is to determine the power value of each box using no more than $\left\lceil \frac{3n}{2} \right\rceil$ queries in total, counting both swap and throw queries.

翻译中…

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 first and the only line of each test case contains a single integer $n$ ($2 \le n \le 1000$) — the number of boxes.

翻译中…

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

翻译中…

Interaction

翻译中…

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

翻译中…

To make a query, output a line in one of the following formats:

翻译中…
  • "swap $x$" (without quotes) ($1 \le x \le n - 1$): Swap the boxes currently located at coordinates $x$ and $x + 1$.
  • "throw $x$" (without quotes) ($1 \le x \le n$): Throw a ball at the box located at coordinate $x$. The jury will respond with an integer representing the number of jumps the ball made before stopping.
翻译中…

Note that queries are case sensitive.

翻译中…

Once you have determined the power value of each box, output a line in the following format:

翻译中…
  • "! $a_1 \space a_2 \space \ldots \space a_n$" (without quotes): Here, $a_i$ is the power value of the box initially located at coordinate $i$ ($1 \le i \le n$). After submitting the final answer, proceed on to the next test case.
翻译中…

Note that submitting the final answer with the previous query does not count towards the limit of $\left\lceil \frac{3n}{2} \right\rceil$ queries.

翻译中…

If your program exceeds $\left\lceil \frac{3n}{2} \right\rceil$ queries in one test case, your program must terminate immediately to receive the verdict Wrong Answer. Otherwise, it may receive any other verdict.

翻译中…

After outputting a query, do not forget to output the end of the line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

翻译中…
  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • sys.stdout.flush() in Python;
  • std::io::stdout().flush() in Rust;
  • see the documentation for other languages.
翻译中…

The interactor is non-adaptive; the power values of the boxes remain constant throughout the interaction.

翻译中…

Hacks

翻译中…

To hack, use the following format.

翻译中…

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

翻译中…

The first line of each test case contains a single integer $n$ ($2 \le n \le 1000$) — the number of boxes.

翻译中…

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \le a_i \le 2$) — the power value of each box.

翻译中…

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

翻译中…

Note

翻译中…

Below is the interaction process in the example:

翻译中…

SolutionJuryExplanation2There are $2$ test cases.4There are $4$ boxes in the first test case. The hidden power values are $a = [2,1,2,1]$.throw 22Throw a ball at the box located at coordinate $2$. The ball travels through coordinates $2 \to 3 \to 5$ and stops at coordinate $5$, so the response is $2$.swap 3Swap the boxes located at coordinate $3$ and $4$. Now box $3$ is located at coordinate $4$ and box $4$ is located at coordinate $3$.throw 23Throw a ball at the box located at coordinate $2$. The ball travels through coordinates $2 \to 3 \to 4 \to 6$ and stops at coordinate $6$, so the response is $3$. Note that the response is different because of the swap.throw 13Throw a ball at the box located at coordinate $1$. The ball travels through coordinates $1 \to 3 \to 4 \to 6$ and stops at coordinate $6$, so the response is $3$.! 2 1 2 1The solution concludes that the power values are $[2,1,2,1]$.2There are $2$ boxes in the second test case. The hidden power values are $a = [1, 2]$.throw 12Throw a ball at the box located at coordinate $1$. The ball travels through coordinates $1 \to 2 \to 4$ and stops at coordinate $4$, so the response is $2$.swap 1Swap the boxes located at coordinate $1$ and $2$. Now box $1$ is located at coordinate $2$ and box $2$ is located at coordinate $1$.throw 11Throw a ball at the box located at coordinate $1$. The ball travels through coordinates $1 \to 3$ and stops at coordinate $3$, so the response is $1$.! 1 2The solution concludes that the power values are $[1,2]$.

翻译中…

Empty lines in the example input and output are given only for better readability; you don't need to output them in your solution.

翻译中…

Note that in the first test case, the given queries are in fact insufficient to uniquely determine the power values; they are given only to illustrate the input/output format.

翻译中…

样例

Input #1
2
4

2

3

3

2

2

1
Output #1
throw 2

swap 3
throw 2

throw 1

! 2 1 2 1

throw 1

swap 1
throw 1

! 1 2
InputCopy OutputCopy
题目信息
题号
2134E
时间限制
2 s
内存限制
256 MB
标签
构造
动态规划
模拟
交互题

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