#P17272. [eJOI 2026] XORting
[eJOI 2026] XORting
题目描述
This is an interactive problem.
Iliyan has played a prank on Jonas: he has hidden a permutation of the integers from to . Jonas is desperate to recover it, and you have agreed to help him.
Iliyan will not reveal the permutation outright, but he will answer questions of the following kind: choose two indices and with , and he tells you the bitwise XOR of and .
The bitwise XOR of two numbers, denoted by , performs logical exclusive OR on every pair of corresponding bits. A result bit is if exactly one input bit is , and otherwise. For example, because . In C++, the XOR of a and b is written a ^ b.
Iliyan is willing to answer at most questions.
These questions cannot always determine the hidden permutation uniquely. A permutation is indistinguishable from if for every pair . Every answer is identical whether the hidden permutation is or , so no sequence of questions can distinguish them. The permutation is always indistinguishable from itself, and there may be no other such permutation.
Your task is to find the lexicographically smallest permutation indistinguishable from .
A permutation is lexicographically smaller than if, at the first position where they differ, . For example, is lexicographically smaller than because their first difference is at and .
The hidden permutation is fixed before your program starts and does not change in response to your questions.
Implementation details
Implement the following function:
std::vector<int> solve(int N)
- : the number of elements in the permutation.
This function is called exactly times, once for each hidden permutation. It must return the lexicographically smallest permutation indistinguishable from the permutation hidden for that call.
To communicate with the jury, you may call:
int get_xor(int i, int j)
Each call returns . Both arguments must be valid indices. Otherwise, your solution receives Output isn't correct: Invalid argument. The function responds in constant time .
The value of is fixed for each subtask and is not passed to your program.
输入格式
Input format:
- line : two integers and , where is either or ;
- the following lines describe the tests:
- line : one integer ;
- line : integers .
If , then ; if , then .
输出格式
Output format:
- line : the permutation returned by your program on the -th test.
提示
Example
Consider the following interaction, in which solve is called twice:
| Participant program | Jury program |
|---|---|
solve(4) |
|
get_xor(0, 1) |
returns 2 |
get_xor(0, 2) |
returns 3 |
get_xor(0, 3) |
returns 1 |
get_xor(1, 2) |
|
get_xor(1, 3) |
returns 3 |
get_xor(2, 3) |
returns 2 |
return {0, 2, 3, 1} |
|
solve(1) |
|
return {0} |
Explanation of the first call
The hidden permutation is , but the lexicographically smallest indistinguishable permutation is . Six questions were asked for , which is allowed because in this subtask.
Explanation of the second call
The only possible permutation for is .
Constraints
- for every , where is the value of in the -th call to
solve - During the -th call to
solve, you may ask at most questions, where is either or , depending on the subtask
Subtasks
| Subtask | Points | Additional constraints | |||
|---|---|---|---|---|---|
| 0 | - | The example. | |||
| 1 | 7 | - | |||
| 2 | 18 | ||||
| 3 | 5 | ||||
| 4 | |||||
| 5 | for some integer . | ||||
| 6 | is odd. | ||||
| 7 | 30 | - | |||
| 8 | 25 | ||||