P
r
o
b
l
e
m
S
t
a
t
e
m
e
n
t
\color{blue}Problem Statement
ProblemStatement
There are
N
N
N Snuke Cats numbered
1
,
2
,
…
,
N
1,2,…,N
1,2,…,N, where
N
N
N is even.
Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.
Recently, they learned the operation called xor (exclusive OR).
We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is ai
. Using this information, restore the integer written on the scarf of each Snuke Cat.
C
o
n
s
t
r
a
i
n
t
s
\color{blue}Constraints
Constraints
All values in input are integers.
2
≤
N
≤
200000
2≤N≤200000
2≤N≤200000,
N
N
N is even.
0
≤
a
i
≤
1
0
9
0≤a_i≤10^9
0≤ai≤109
There exists a combination of integers on the scarfs that is consistent with the given information.
I
n
p
u
t
\color{blue}Input
Input
Input is given from Standard Input in the following format:
N
a1
a2
…
aN
O
u
t
p
u
t
\color{blue}Output
Output
Print a line containing
N
N
N integers separated with space.
The i-th of the integers from the left should represent the integer written on the scarf of Snuke Cat i.
If there are multiple possible solutions, you may print any of them.
根据题目意思和样例解释,我们可以得到以下式子:
设
a
i
a_i
ai为题目给出的,
b
i
b_i
bi为答案
a
1
=
b
2
⊕
b
3
⊕
b
4
⊕
.
.
.
b
n
a_1=b_2 \oplus b_3 \oplus b_4 \oplus ...b_n
a1=b2⊕b3⊕b4⊕...bn
a
2
=
b
1
⊕
b
3
⊕
b
4
⊕
.
.
.
b
n
a_2=b_1 \oplus b_3 \oplus b_4 \oplus ...b_n
a2=b1⊕b3⊕b4⊕...bn
.
.
.
...
...
a
n
=
b
1
⊕
b
2
⊕
b
3
⊕
.
.
.
b
n
−
1
a_n=b_1 \oplus b_2 \oplus b_3 \oplus ... b_{n-1}
an=b1⊕b2⊕b3⊕...bn−1
因为
n
n
n是个偶数,所以根据上面的式子,易得:
a
1
⊕
a
2
⊕
a
3
.
.
⊕
a
n
=
b
1
⊕
b
2
⊕
b
3
.
.
.
.
⊕
b
n
a_1 \oplus a_2 \oplus a_3..\oplus a_n = b_1 \oplus b_2 \oplus b_3 ....\oplus b_n
a1⊕a2⊕a3..⊕an=b1⊕b2⊕b3....⊕bn
我们设它等于
X
X
X
因为
a
1
=
b
2
⊕
b
3
⊕
b
4
⊕
.
.
.
b
n
a_1=b_2 \oplus b_3 \oplus b_4 \oplus ...b_n
a1=b2⊕b3⊕b4⊕...bn,再根据
a
⊕
a
=
0
a \oplus a=0
a⊕a=0,
0
⊕
a
=
a
0 \oplus a=a
0⊕a=a,所以可以得到
a
1
=
X
⊕
b
1
a_1=X \oplus b_1
a1=X⊕b1,也就是
b
1
=
a
1
⊕
X
b_1=a_1 \oplus X
b1=a1⊕X。
同理可得,
b
i
=
X
⊕
a
i
b_i=X \oplus a_i
bi=X⊕ai。
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;
#define endl '\n'
#define pb(a) push_back(a)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) int(x.size())
#define IOS ios::sync_with_stdio(0);
int n;
int a[N],b[N];
int main() {
scanf("%d",&n);
int x=0;
for(int i=1;i<=n;++i) scanf("%d",&a[i]),x^=a[i];
for(int i=1;i<=n;++i) {
b[i] = x^a[i];
}
for(int i=1;i<=n;++i) printf("%d ",b[i]);
return 0;
}