luogu#P11008. 『STA - R7』异或生成序列
『STA - R7』异或生成序列
Problem Description
For a permutation of , define its XOR-generated sequence as a non-negative integer sequence of length , generated as follows:
Here, denotes the bitwise XOR operation. In C++, it is represented by the ^ operator.
Given and , you need to construct a corresponding permutation .
The input guarantees that a solution exists. If multiple solutions exist, output any one.
Input Format
This problem contains multiple test cases in a single test file.
The first line contains a positive integer , representing the number of test cases.
For each test case:
-
The first line contains a positive integer .
-
The second line contains non-negative integers, representing the XOR-generated sequence .
Output Format
For each test case, output one line with positive integers, representing a corresponding permutation . If multiple solutions exist, output any one.
2
4
1 2 5
6
1 7 3 2 5
2 3 1 4
3 2 5 6 4 1
Hint
[Sample Explanation]
For the first test case, we have:
- $b_1 = p_1 \operatorname{xor} p_2 = 2 \operatorname{xor} 3 = 1$
- $b_2 = p_2 \operatorname{xor} p_3 = 3 \operatorname{xor} 1 = 2$
- $b_3 = p_3 \operatorname{xor} p_4 = 1 \operatorname{xor} 4 = 5$
Therefore, the resulting sequence is the same as the input, so this permutation satisfies the requirement.
For the second test case, is also a valid permutation.
[Constraints]
This problem uses bundled tests.
For of the data:
- ;
- ;
- ;
- It is guaranteed that at least one valid solution exists.
The detailed subtask distribution is as follows:
| Subtask ID | Constraints | Score |
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | No special constraints |
[Notes]
The input file for this problem is large. Please use a faster input method.
Translated by ChatGPT 5