A16254 | Salyg1n and Array (simple version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
This is the simple version of the problem. The only difference between the versions is the limit on the number of queries. In this version, you can make no more than 100 queries. You can make hacks only if both versions of the problem are solved.
This is an interactive problem!
salyg1n has given you a positive integer $k$ and wants to play a game with you. He has chosen an array of $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 10^9$ ). You must print $a_1 \oplus a_2 \oplus \ldots \oplus a_n$ , where $\oplus$ denotes the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operation. You can make queries of the following type:
- $?$ $i$ : in response to this query, you will receive $a_i \oplus a_{i + 1} \oplus \ldots \oplus a_{i + k - 1}$ . Also, after this query, the subarray $a_i, a_{i + 1}, \ldots, a_{i + k - 1}$ will be reversed, i.e., the chosen array $a$ will become: $a_1, a_2, \ldots a_{i - 1}, a_{i + k - 1}, a_{i + k - 2}, \ldots, a_{i + 1}, a_i, a_{i + k}, \ldots, a_n$ .
You can make no more than $100$ queries to answer the problem.
This is an interactive problem!
salyg1n has given you a positive integer $k$ and wants to play a game with you. He has chosen an array of $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 10^9$ ). You must print $a_1 \oplus a_2 \oplus \ldots \oplus a_n$ , where $\oplus$ denotes the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operation. You can make queries of the following type:
- $?$ $i$ : in response to this query, you will receive $a_i \oplus a_{i + 1} \oplus \ldots \oplus a_{i + k - 1}$ . Also, after this query, the subarray $a_i, a_{i + 1}, \ldots, a_{i + k - 1}$ will be reversed, i.e., the chosen array $a$ will become: $a_1, a_2, \ldots a_{i - 1}, a_{i + k - 1}, a_{i + k - 2}, \ldots, a_{i + 1}, a_i, a_{i + k}, \ldots, a_n$ .
You can make no more than $100$ queries to answer the problem.
输入格式
The first line contains a single integer $t$ ( $1 \leq t \leq 1000$ ) – the number of test cases.
输出格式
The interaction between your program and the jury's program begins with reading two positive even integers $n$ and $k$ ( $1 \leq k \leq n \leq k^2 \leq 2500$ ) – the length of the chosen array and the length of the query subarray, respectively.
To find the value of $a_i \oplus a_{i + 1} \oplus \ldots \oplus a_{i + k - 1}$ , print the query in the format $?$ $i$ ( $1 \leq i \leq n - k + 1$ ). Then read a single integer – the answer to your query.
You can make no more than $100$ queries. When you are ready to print the answer, output it in the format $!$ $x$ . After that, proceed to process the next test case or terminate the program if it was the last test case. Printing the answer does not count as one of the $100$ queries.
If your program makes more than $100$ queries for one set of input data, or makes an invalid query, then the response to the query will be -1. After receiving such a response, your program should immediately terminate to receive the verdict Wrong Answer. Otherwise, it may receive any other verdict.
After printing a query do not forget to output the end of 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;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see the documentation for other languages.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10000$ . The interactor in this problem is not adaptive.Hacks:
To perform a hack, use the following format:
The first line contains a single integer $t$ – the number of test cases.
The description of each test case should consist of two lines. The first line contains the numbers $n$ and $k$ – the length of the chosen array and the length of the query subarray, respectively. The second line contains $n$ numbers $a_1, a_2, \ldots, a_n$ – the array that the jury should choose for this test case.
To find the value of $a_i \oplus a_{i + 1} \oplus \ldots \oplus a_{i + k - 1}$ , print the query in the format $?$ $i$ ( $1 \leq i \leq n - k + 1$ ). Then read a single integer – the answer to your query.
You can make no more than $100$ queries. When you are ready to print the answer, output it in the format $!$ $x$ . After that, proceed to process the next test case or terminate the program if it was the last test case. Printing the answer does not count as one of the $100$ queries.
If your program makes more than $100$ queries for one set of input data, or makes an invalid query, then the response to the query will be -1. After receiving such a response, your program should immediately terminate to receive the verdict Wrong Answer. Otherwise, it may receive any other verdict.
After printing a query do not forget to output the end of 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;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see the documentation for other languages.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10000$ . The interactor in this problem is not adaptive.Hacks:
To perform a hack, use the following format:
The first line contains a single integer $t$ – the number of test cases.
The description of each test case should consist of two lines. The first line contains the numbers $n$ and $k$ – the length of the chosen array and the length of the query subarray, respectively. The second line contains $n$ numbers $a_1, a_2, \ldots, a_n$ – the array that the jury should choose for this test case.
输入输出样例
输入 #1
2 4 2 6 4 6 6 4
输出 #1
? 1 ? 3 ! 2 ? 1 ! 4
In the first test case, the jury has chosen the array $a$ $=$ $[4, 2, 5, 1]$
In the second test case, the jury has chosen the array $a$ $=$ $[5, 7, 1, 3, 3, 7]$
In the second test case, the jury has chosen the array $a$ $=$ $[5, 7, 1, 3, 3, 7]$
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted