P17541 [CodeChef] FINDABC
提高-
题目描述

Chef has 3 hidden numbers A, B, and C such that 0 ≤ A, B, C ≤ N.

Let f be a function such that $f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus$ denotes the [bitwise XOR] operation.

Given the values of $f(0), f(1), \dots, f(N),$ determine the values of A, B, and C.

It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one.

------ Input Format ------

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of multiple lines of input.
  • The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C.
  • Next line contains $N+1 space-separated integers denoting f(0), f(1), \dots, f(N)$.

------ Output Format ------

For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one.

------ Constraints ------

$1 ≤ T ≤ 2 \cdot 10^{4}$
$2 ≤ N ≤ 10^{5}$
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.

----- Sample Input 1 ------
3
2
0 3 6
2
4 7 2
5
9 6 11 8 13 10

----- Sample Output 1 ------
0 0 0
2 0 2
1 3 5

----- explanation 1 ------
Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as:
- $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$.
- $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$.
- $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$.

Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as:
- $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$.
- $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$.
- $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$.

Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as:
- $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$.
- $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$.
- $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$.
- $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$.
- $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$.
- $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.

输入格式

见题面

输出格式

见题面

样例输入
3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10
样例输出
0 0 0 2 0 2 1 3 5