传递 GCDAI (CI翻译)
This is a run-twice (communication) interactive problem.
这是一道运行两次(通信)交互题。AI (CI翻译)
There are two players: Ja the Ghost and Quack the Duck. The jury (otherwise known as the interactor of this problem) will first interact with Ja. After Ja ends the interaction, the jury will interact with Quack. Note that Ja and Quack may not directly pass information to each other; both players are only able to send information to or receive information from the jury.
有两名选手:幽灵 Ja 和鸭子 Quack。评测器(也称为本题的交互器)首先与 Ja 进行交互。Ja 结束交互后,评测器将与 Quack 进行交互。注意,Ja 和 Quack 不能直接互相传递信息;两名选手都只能向评测器发送信息,或从评测器接收信息。AI (CI翻译)
Before the interaction, the jury determines an integer $n$ and an array of $n$ positive integers $a_1, a_2, \ldots, a_n$. These values are consistent across both players.
在交互开始前,评测器确定一个整数 $n$ 和一个包含 $n$ 个正整数的数组 $a_1, a_2, \ldots, a_n$。这些值对于两名选手始终相同。AI (CI翻译)
Ja receives $n$ and an array of $n$ positive integers $a_1, a_2, \ldots, a_n$ from the jury, which he wants to send to Quack, where $a_i \le 10^6$. To do this, Ja will select an integer $k$, where $$k \le \left\lceil \frac{10n}{9} \right\rceil + 150,$$ and create an array of positive integers $b_1, b_2, \ldots, b_k$, where $b_i \le 10^6$, and send it back to the jury. Then the jury will give Quack the integers $n$ and $k$. Quack can ask the jury at most $180n + 150$ queries in the following form:
Ja 从评测器处接收 $n$ 和一个包含 $n$ 个正整数的数组 $a_1, a_2, \ldots, a_n$,他的目标是将其传递给 Quack,其中 $a_i \le 10^6$。为此,Ja 选择一个整数 $k$,满足 $$k \le \left\lceil \frac{10n}{9} \right\rceil + 150,$$ 并构造一个包含 $k$ 个正整数的数组 $b_1, b_2, \ldots, b_k$,其中 $b_i \le 10^6$,然后将其发送回评测器。之后,评测器会将整数 $n$ 和 $k$ 交给 Quack。Quack 最多可以进行 $180n + 150$ 次如下形式的询问:AI (CI翻译)
- Choose any two integers
$i$and$j$($1 \le i, j \le k$,$i \neq j$), and the jury will respond with$\mathrm{gcd}(b_i, b_j)$.
- 选择任意两个整数
$i$和$j$($1 \le i, j \le k$且$i \neq j$),评测器将返回$\mathrm{gcd}(b_i, b_j)$。
Here, $\gcd(x, y)$ denotes the greatest common divisor (GCD) of integers $x$ and $y$.
其中,$\gcd(x, y)$ 表示整数的最大公约数(GCD)。AI (CI翻译)
Note that both $a$ and $b$ are hidden from Quack; Quack can only get information from queries.
注意,Quack 无法直接看到 $a$ 和 $b$,只能通过询问获取信息。AI (CI翻译)
Ja wants to ensure that Quack can determine the original array $a$. Your task is to act as both players and determine an optimal interaction strategy for both players so that Quack determines the original array $a$ correctly.
Ja 希望确保 Quack 能够确定原数组 $a$。你的任务是同时扮演两名选手,为两名选手设计一种最优的交互策略,使 Quack 能够正确确定原数组 $a$。AI (CI翻译)
First Run
第一次运行AI (CI翻译)
Your code will run exactly twice on each test. On the first run, you will be Ja.
对于每组测试数据,你的代码将恰好运行两次。第一次运行时,你将扮演 Ja。AI (CI翻译)
Input
输入格式AI (CI翻译)
The first line of the input contains the string first. The purpose of this is so your program recognizes that this is its first run, and it should act as Ja.
输入第一行包含字符串 first。该字符串用于让程序识别当前是第一次运行,此时程序应扮演 Ja。AI (CI翻译)
The second line contains the number of test cases $t$ ($1 \le t \le 100$). The description of the test cases follows.
第二行包含测试用例数量 $t$($1 \le t \le 100$)。接下来是各测试用例的描述。AI (CI翻译)
The first line of the $i$-th test case contains an integer $n$ ($1 \le n \le 10^3$) — the length of $a$ for the $i$-th test case.
第 $i$ 个测试用例的第一行包含一个整数 $n$($1 \le n \le 10^3$)——该测试用例中 $a$ 的长度。AI (CI翻译)
The second line of the $i$-th test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$) — the array $a$.
第 $i$ 个测试用例的第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($1 \le a_i \le 10^6$)——数组 $a$。AI (CI翻译)
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^3$.
保证所有测试用例的 $n$ 之和不超过 $10^3$。AI (CI翻译)
Output
输出格式AI (CI翻译)
For each test case, first print an integer $k$ ($1 \le k \le \left\lceil \frac{10n}{9} \right\rceil + 150$), denoting the length of the array $b$. Then print $k$ integers $b_1, b_2, \ldots, b_k$ ($1 \le b_i \le 10^6$), denoting the array $b$ that Ja will send to the jury. This array will be used to answer the queries in the second run.
对于每个测试用例,首先输出一个整数 $k$($1 \le k \le \left\lceil \frac{10n}{9} \right\rceil + 150$),表示数组 $b$ 的长度。然后输出 $k$ 个整数 $b_1, b_2, \ldots, b_k$($1 \le b_i \le 10^6$),表示 Ja 将发送给评测器的数组 $b$。该数组将在第二次运行中用于回答询问。AI (CI翻译)
After this, proceed to the next test case or terminate your program if it was the last test case.
之后,继续处理下一个测试用例;如果这是最后一个测试用例,则终止程序。AI (CI翻译)
Second Run
第二次运行AI (CI翻译)
On the second run, you are Quack.
第二次运行时,你将扮演 Quack。AI (CI翻译)
Input
输入格式AI (CI翻译)
The first line of the input contains the string second. The purpose of this is so your program recognizes that this is its second run, and it should act as Quack.
输入第一行包含字符串 second。该字符串用于让程序识别当前是第二次运行,此时程序应扮演 Quack。AI (CI翻译)
The second line of the input contains exactly one integer $t$ ($1 \le t \le 100$) — the number of test cases. Note that this number is equal to $t$ from the first run input.
第二行恰好包含一个整数 $t$($1 \le t \le 100$)——测试用例数量。注意,该数值与第一次运行输入中的 $t$ 相同。AI (CI翻译)
The first line of each test case contains two integers $n$ and $k$ ($1 \le n \le 10^3$, $1 \le k \le \left\lceil \frac{10n}{9} \right\rceil + 150$). This denotes the lengths of $a$ and $b$, respectively.
每个测试用例的第一行包含两个整数 $n$ 和 $k$($1 \le n \le 10^3$,$1 \le k \le \left\lceil \frac{10n}{9} \right\rceil + 150$),分别表示 $a$ 和 $b$ 的长度。AI (CI翻译)
Note that the test cases in the second run may be shuffled. Please see the example test case for further illustration.
注意,第二次运行中的测试用例顺序可能发生改变。更多说明请参见样例测试用例。AI (CI翻译)
Interaction
交互AI (CI翻译)
For the $i$-th test case, recall that you will first receive $n$ and $k$ in the input from the jury according to the input format above. After receiving those inputs, you will be able to make at most $180n + 150$ queries of the following form:
对于第 $i$ 个测试用例,按照上述输入格式,你将首先从评测器处接收 $n$ 和 $k$。接收到这些输入后,你最多可以进行 $180n + 150$ 次如下形式的询问:AI (CI翻译)
? i j($1 \leq i, j \leq k$,$i \neq j$).
? i j($1 \leq i, j \leq k$且$i \neq j$)。
After each query, the jury will respond with $\mathrm{gcd}(b_i, b_j)$, which you should read through the input stream.
每次询问后,评测器会返回 $\mathrm{gcd}(b_i, b_j)$,你应当从输入流中读取该返回值。AI (CI翻译)
If your program makes more than $180n + 150$ queries, your program should immediately terminate and receive the verdict Wrong Answer. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
如果程序进行的询问次数超过 $180n + 150$,程序应立即终止,并获得 Wrong Answer 评判。否则,由于你的程序会继续从已关闭的输入流中读取内容,你可能会获得任意评判结果。AI (CI翻译)
Once you are ready to report the original array $a$, you may do so in the following format:
当你准备好报告原数组 $a$ 时,可以使用以下格式:AI (CI翻译)
! $a_1, a_2, \ldots ,a_n$($1 \leq a_i \leq 10^6$).
! $a_1, a_2, \ldots ,a_n$($1 \leq a_i \leq 10^6$)。
Then, you will either proceed to the next test case, or your program must terminate if you have processed every test case.
之后,继续处理下一个测试用例;如果已经处理完所有测试用例,则程序必须终止。AI (CI翻译)
The interactor is not adaptive. That is, both arrays $a$ and $b$ will not change during the interaction and will always be the same arrays as in the first run.
交互器不是自适应的。也就是说,数组 $a$ 和 $b$ 在交互过程中不会发生改变,并且始终与第一次运行中的数组相同。AI (CI翻译)
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.
每次输出询问后,不要忘记输出换行并刷新$^{\text{∗}}$输出。否则,你将得到 Idleness limit exceeded 评判。AI (CI翻译)
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.
如果在交互的任何一步中,读取到 $-1$ 而不是有效数据,你的程序必须立即退出。这意味着你的程序将因无效询问或其他错误而收到 Wrong answer。如果不退出,由于你的程序会继续从已关闭的输入流中读取内容,可能会得到任意评判结果。AI (CI翻译)
$^{\text{∗}}$To flush, use: fflush(stdout) or cout.flush() in C++; sys.stdout.flush() in Python; see the documentation for other languages.
$^{\text{∗}}$刷新输出的方法:在 C++ 中使用 fflush(stdout) 或 cout.flush();在 Python 中使用 sys.stdout.flush();其他语言请参阅相应文档。AI (CI翻译)
Note
说明
AI (CI翻译)In the first run, there are two test cases.
在第一次运行中,有两个测试用例。AI (CI翻译)
For the first test case, Ja is given $a = [1, 1, 4, 5, 1, 4]$. He decides to send $b = [20, 1, 1, 4, 5, 1, 4]$.
对于第一个测试用例,Ja 得到 $a = [1, 1, 4, 5, 1, 4]$。他决定发送 $b = [20, 1, 1, 4, 5, 1, 4]$。AI (CI翻译)
For the second test case, Ja is given $a = [2, 6, 10]$. He decides to send $b = [30, 2, 6, 10]$.
对于第二个测试用例,Ja 得到 $a = [2, 6, 10]$。他决定发送 $b = [30, 2, 6, 10]$。AI (CI翻译)
In the second run, the order of the test cases is shuffled. Therefore, Quack first receives the test case with $n = 3$ and $k = 4$. He asks $\mathrm{gcd}(b_1, b_i)$ for $i = 2, 3, 4$, and the jury answers $2, 6, 10$. Thus, Quack can determine that the original array is $[2, 6, 10]$.
在第二次运行中,测试用例的顺序发生了改变。因此,Quack 首先接收到 $n = 3$ 和 $k = 4$ 的测试用例。他询问 $\mathrm{gcd}(b_1, b_i)$,其中 $i = 2, 3, 4$,评测器返回 $2, 6, 10$。于是,Quack 可以确定原数组为 $[2, 6, 10]$。AI (CI翻译)
Then Quack receives the test case with $n = 6$ and $k = 7$. He asks $\mathrm{gcd}(b_1, b_i)$ for $i = 2, 3, 4, 5, 6, 7$, and the jury answers $1, 1, 4, 5, 1, 4$. Thus, Quack can determine that the original array is $[1, 1, 4, 5, 1, 4]$.
随后,Quack 接收到 $n = 6$ 和 $k = 7$ 的测试用例。他询问 $\mathrm{gcd}(b_1, b_i)$,其中 $i = 2, 3, 4, 5, 6, 7$,评测器返回 $1, 1, 4, 5, 1, 4$。于是,Quack 可以确定原数组为 $[1, 1, 4, 5, 1, 4]$。AI (CI翻译)
This example illustrates that although the test cases in the second run may appear in a different order, the same arrays $a$ and $b$ from the first run are used.
该样例说明,尽管第二次运行中的测试用例顺序可能不同,但使用的仍然是第一次运行中的相同数组 $a$ 和 $b$。AI (CI翻译)
样例
first
2
6
1 1 4 5 1 4
3
2 6 10
7
20 1 1 4 5 1 4
4
30 2 6 10
second
2
3 4
2
6
10
6 7
1
1
4
5
1
4
? 1 2
? 1 3
? 1 4
! 2 6 10
? 1 2
? 1 3
? 1 4
? 1 5
? 1 6
? 1 7
! 1 1 4 5 1 4
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。