#P9227. 异或积
异或积
Background
Little H learned about the XOR operation in class.
For two non-negative integers , their XOR is defined as follows: treat them as binary numbers, and for each bit position compute the result bit by bit:
- If the bits of and at this position are different, the result bit is .
- If the bits of and at this position are the same, the result bit is .
The XOR of and is written as or .
In C++, you can use x ^ y to get the XOR value of and .
Also, the XOR of multiple numbers is called the XOR sum.
Problem Description
Little H also learned that the XOR product of a sequence of length is a sequence of the same length, where equals the XOR sum of all elements in except , that is,
For example, the XOR product of the sequence is .
A XOR product transformation means replacing a sequence with its XOR product. Since the sequence length does not change after a transformation, the XOR product transformation can be applied multiple times in a row.
Now, Little H has a sequence of length . He wants you to help him compute the sequence obtained after applying XOR product transformations to .
Input Format
This problem contains multiple test cases within a single test point.
The first line contains an integer , the number of test cases.
For each test case:
The first line contains two integers .
The second line contains integers .
Output Format
For each test case:
Output one line with integers, representing the sequence obtained after applying XOR product transformations to sequence .
1
4 1
1 2 3 4
5 6 7 0
1
4 2
0 0 0 1
0 0 0 1
见附件中的 samples/xor3.in
见附件中的 samples/xor3.ans
Hint
Explanation for Sample 1
This sample is exactly the example given in the statement.
Explanation for Sample 2
After the 1st XOR product transformation: ;
After the 2nd XOR product transformation: .
Constraints
For of the testdata, , , , .
| Test Point ID | Special Property | ||
|---|---|---|---|
| The XOR sum of all numbers in is | |||
| is odd | |||
| is even | |||
Notes
In C++, for the range , you can:
- Use
unsigned int xto define it. - Use
cin >> xorscanf("%u", &x)for input. - Use
cout << xorprintf("%u", x)for output.
Translated by ChatGPT 5