Codeforces Round 1066 (Div. 1 + Div. 2)
G
Isaac's Queries
Codeforces
2800
原题
← FH →
翻译中…

You have reached the final level of the popular roguelike game "Isaac's Keybindings". Instead of a boss, you encounter a shopkeeper who holds an hidden array of integers $a_1, a_2, \ldots, a_n$, where $0 \leq a_i \lt 2^{30}$ for each $i$ in $[1, n]$.

翻译中…

It is guaranteed that the array is generated randomly, i.e., each $a_i$ ($1 \leq i \leq n$) is an integer independently generated uniformly at random in $[0, 2^{30})$, in all the tests excluding the example.

翻译中…

Let $f(u, v) = a_u \oplus a_{u+1} \oplus \ldots \oplus a_v$, where $\oplus$ is the bitwise $\texttt{XOR}$.

翻译中…

You can ask queries of the following form: $\texttt{? u v}$, with $1 \leq u \leq v \leq n$.

翻译中…

The answer to the query is:

翻译中…
  • $-1$, if $f(u, v) = 0$;
  • $\lfloor \log_2(f(u, v)) \rfloor$ otherwise.
翻译中…

Each query has a cost of $\frac{1}{v-u+1}$ robocoins. On each test, you are given $300$ robocoins in total to pass at most $30$ test cases (that is, you can spend $10$ robocoins on average for a single test case). If your balance ever becomes negative you lose. Note that your robocoin balance does not need to be an integer at any moment.

翻译中…

Find the answer to all possible $\frac{n(n+1)}{2}$ queries without losing.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains one integer $n$ ($n = 3$ or $n = 100$) — the length of the array $a_1, a_2, \ldots, a_n$. It is guaranteed that the array is generated randomly in all the tests excluding the example.

翻译中…

There are exactly $50$ tests in this problem (including the example). The example has $t = 1$ and $n = 3$, and all the other tests have $t = 30$ and $n = 100$.

翻译中…

Hacks are not allowed in this problem.

翻译中…

Interaction

翻译中…

For each test case, first read a single integer $n$. If the integer you read is $-2$, it means that the answer to the previous test case was wrong, and you should exit immediately.

翻译中…

To ask a query, print a line in the format $\texttt{? u v}$ with $1 \leq u \leq v \leq n$.

翻译中…

As a response to the query, you will receive $-2$ if you made an invalid query (i.e., the format is invalid, or you would reach a negative amount of robocoins). In that case, you should exit immediately. Otherwise, you will receive the answer to the query.

翻译中…

When you determine the answers to all the $\frac{n(n+1)}{2}$ queries, print them in the following format.

翻译中…

Print $n+1$ lines. The first line must contain a single character $\texttt{!}$. The $i$-th of the next $n$ lines must contain $n-i+1$ integers: the answers to queries $\texttt{? i i}, \, \texttt{? i i+1}, \,\ldots, \, \texttt{? i n}$, respectively.

翻译中…

After printing a query, do not forget to output the end of line and flush the output. Otherwise, you will get $\texttt{Idleness limit exceeded}$. To do this, use:

翻译中…
  • $\texttt{fflush(stdout)}$ or $\texttt{cout.flush()}$ in C++;
  • $\texttt{System.out.flush()}$ in Java;
  • $\texttt{stdout.flush()}$ in Python;
  • see the documentation for other languages.
翻译中…

Note

翻译中…

In the example, the hidden array is $[a_1, a_2, a_3] = [2, 4, 6]$.

翻译中…
  • First, you ask $\texttt{? 1 2}$. Since $f(1, 2) = a_1 \oplus a_2 = 6$, the answer is $\lfloor \log_2(6) \rfloor = 2$.
  • Then, you ask $\texttt{? 1 3}$. Since $f(1, 3) = a_1 \oplus a_2 \oplus a_3 = 0$, the answer is $-1$.
  • Then, you ask $\texttt{? 2 3}$. Since $f(2, 3) = a_2 \oplus a_3 = 2$, the answer is $\lfloor \log_2(2) \rfloor = 1$.
翻译中…

Now, even without knowing the hidden array, you claim the answer to all the possible $6$ queries. For example, you claim that the answer to $\texttt{? 1 1}$ is $1$.

翻译中…

You have spent $1/2 + 1/3 + 1/2 = 4/3$ robocoins, which is less than the allowed $300$ robocoins.

翻译中…

样例

Input #1
1
3

2

-1

1
Output #1
? 1 2

? 1 3

? 2 3

!
1 2 -1
2 1
2
InputCopy OutputCopy
题目信息
题号
2157G
时间限制
4 s
内存限制
256 MB
标签
位运算
暴力
构造
DFS 及类似
分治
动态规划
贪心
交互题
数学
概率论

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