2 条题解
-
3
题目分析
首先,我们要知道一个基本的定理:
这是因为异或相同为 ,不同为 。所以两个相同的数异或的值为 。
知道了这个之后,我们就可以把题目中的式子全部都异或起来,变成这样:
$$\overbrace{(a_1\oplus a_1\oplus \ldots \oplus a_1)}^{n-1}\oplus \overbrace{(a_2\oplus a_2\oplus \ldots \oplus a_2)}^{n-1}\oplus \ldots \oplus \overbrace{(a_n\oplus a_n\oplus \ldots \oplus a_n)}^{n-1}=b_1\oplus b_2\oplus \ldots\oplus b_n $$因为 是偶数,所以可以化简成:
$$a_1\oplus a_2\oplus \ldots \oplus a_n=b_1\oplus b_2\oplus \ldots \oplus b_n $$我们令 为 ,则:
把这个式子和题目中第一个式子异或,得:
$$a_1\oplus (a_2\oplus a_2)\oplus (a_3\oplus a_3)\oplus \ldots \oplus (a_n\oplus a_n)=x\oplus b_1 $$化简一下,得:
同理可证,。
于是,我们就可以得出答案了。
AC 代码
#include<bits/stdc++.h> using namespace std; int a[200100]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,k=0; cin>>n; for (int i=1;i<=n;i++) { cin>>a[i]; k^=a[i]; } for (int i=1;i<=n;i++) cout<<(k^a[i])<<' '; return 0; }
信息
- ID
- 647
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 3
- 标签
- 递交数
- 8
- 已通过
- 7
- 上传者