#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 , where for each in .
It is guaranteed that the array is generated randomly, i.e., is a uniformly random integer in for each in , in all the tests excluding the example.
Let $f(u, v) = a_u \oplus a_{u+1} \oplus \ldots \oplus a_v$, where is the bitwise XOR.
You can ask queries of the following form: ? u v, with .
The answer to the query is:
- , if ;
- otherwise.
Each query has a cost of robocoins. You initially have 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 queries without losing.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains one integer () — the length of the array . It is guaranteed that the array is generated randomly in all the tests excluding the example.
There are exactly tests in this problem (including the example). The example has and , and all the other tests have and .
INTERACTION
For each test case, first read a single integer . If the integer you read is , 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 .
As a response to the query, you will receive 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 queries, print them in the following format.
Print lines. The first line must contain a single character !. The -th of the next lines must contain 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)orcout.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 .
- First, you ask
? 1 2. Since , the answer is . - Then, you ask
? 1 3. Since , the answer is . - Then, you ask
? 2 3. Since , the answer is .
Now, even without knowing the hidden array, you claim the answer to all the possible queries. For example, you claim that the answer to ? 1 1 is .
You have spent $\frac{1}{2} + \frac{1}{3} + \frac{1}{2} = \frac{4}{3}$ robocoins, which is less than the allowed robocoins.