#P15143. [SWERC 2025] Isaac's Queries

[SWERC 2025] Isaac's Queries

题目描述

You have reached the final level of the popular roguelike game “Isaac’s Keybindings”. Instead of a boss, you encounter a shopkeeper who holds a hidden array of integers a1,a2,,ana_1, a_2, \ldots, a_n, where 0ai<2300 \le a_i < 2^{30} for each ii in [1,n][1, n].

It is guaranteed that the array is generated randomly, i.e., aia_i is a uniformly random integer in [0,230)[0, 2^{30}) for each ii in [1,n][1, n], 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 XOR.

You can ask queries of the following form: ? u v, with 1uvn1 \le u \le v \le n.

The answer to the query is:

  • 1-1, if f(u,v)=0f(u, v) = 0;
  • log2(f(u,v))\lfloor \log_2(f(u, v)) \rfloor otherwise.

Each query has a cost of 1vu+1\frac{1}{v - u + 1} robocoins. You initially have 3535 robocoins and 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 n(n+1)2\frac{n(n+1)}{2} queries without losing.

输入格式

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

The first line of each test case contains one integer nn (1n1001 \le n \le 100) — the length of the array a1,a2,,ana_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 5050 tests in this problem (including the example). The example has t=1t = 1 and n=3n = 3, and all the other tests have t=30t = 30 and n=100n = 100.

INTERACTION

For each test case, first read a single integer nn. If the integer you read is 2-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 ? u v with 1uvn1 \le u \le v \le n.

As a response to the query, you will receive 2-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 n(n+1)2\frac{n(n+1)}{2} queries, print them in the following format.

Print n+1n + 1 lines. The first line must contain a single character !. The ii-th of the next nn lines must contain ni+1n - i + 1 integers: the answers to queries ? i i, ? i i+1, ..., ? i n, respectively.

After printing a query, do not forget to output the end of line and flush the output. To do this, use:

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

输出格式

See Interaction

1
3
2 4 6

? 1 2

? 1 3

? 2 3

!
1 2 -1
2 1
2

提示

Explanation of sample 1.

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

  • First, you ask ? 1 2. Since f(1,2)=a1a2=6f(1,2) = a_1 \oplus a_2 = 6, the answer is log2(6)=2\lfloor \log_2(6) \rfloor = 2.
  • Then, you ask ? 1 3. Since f(1,3)=a1a2a3=0f(1,3) = a_1 \oplus a_2 \oplus a_3 = 0, the answer is 1-1.
  • Then, you ask ? 2 3. Since f(2,3)=a2a3=2f(2,3) = a_2 \oplus a_3 = 2, the answer is log2(2)=1\lfloor \log_2(2) \rfloor = 1.

Now, even without knowing the hidden array, you claim the answer to all the possible 66 queries. For example, you claim that the answer to ? 1 1 is 11.

You have spent $\frac{1}{2} + \frac{1}{3} + \frac{1}{2} = \frac{4}{3}$ robocoins, which is less than the allowed 3535 robocoins.