A13318 | Present
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realized that she couldn't compute it for a very large array, thus she asked for your help. Can you do it? Formally, you need to compute
$$$$ (a_1 + a_2) \oplus (a_1 + a_3) \oplus \ldots \oplus (a_1 + a_n) \\ \oplus (a_2 + a_3) \oplus \ldots \oplus (a_2 + a_n) \\ \ldots \\ \oplus (a_{n-1} + a_n) \\ $$ </p><p>Here $x \\oplus y$ is a bitwise XOR operation (i.e. $x$ <span class="tex-font-style-tt">^</span> $y$$$ in many modern programming languages). You can read about it in Wikipedia: [https://en.wikipedia.org/wiki/Exclusive\_or#Bitwise\_operation](https://en.wikipedia.org/wiki/Exclusive_or#Bitwise_operation).
$$$$ (a_1 + a_2) \oplus (a_1 + a_3) \oplus \ldots \oplus (a_1 + a_n) \\ \oplus (a_2 + a_3) \oplus \ldots \oplus (a_2 + a_n) \\ \ldots \\ \oplus (a_{n-1} + a_n) \\ $$ </p><p>Here $x \\oplus y$ is a bitwise XOR operation (i.e. $x$ <span class="tex-font-style-tt">^</span> $y$$$ in many modern programming languages). You can read about it in Wikipedia: [https://en.wikipedia.org/wiki/Exclusive\_or#Bitwise\_operation](https://en.wikipedia.org/wiki/Exclusive_or#Bitwise_operation).
输入格式
The first line contains a single integer $n$ ( $2 \leq n \leq 400\,000$ ) — the number of integers in the array.
The second line contains integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 10^7$ ).
The second line contains integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 10^7$ ).
输出格式
Print a single integer — xor of all pairwise sums of integers in the given array.
输入输出样例
输入 #1
2 1 2
输出 #1
3
输入 #2
3 1 2 3
输出 #2
2
In the first sample case there is only one sum $1 + 2 = 3$ .
In the second sample case there are three sums: $1 + 2 = 3$ , $1 + 3 = 4$ , $2 + 3 = 5$ . In binary they are represented as $011_2 \oplus 100_2 \oplus 101_2 = 010_2$ , thus the answer is 2.
$\oplus$ is the bitwise xor operation. To define $x \oplus y$ , consider binary representations of integers $x$ and $y$ . We put the $i$ -th bit of the result to be 1 when exactly one of the $i$ -th bits of $x$ and $y$ is 1. Otherwise, the $i$ -th bit of the result is put to be 0. For example, $0101_2 \, \oplus \, 0011_2 = 0110_2$ .
In the second sample case there are three sums: $1 + 2 = 3$ , $1 + 3 = 4$ , $2 + 3 = 5$ . In binary they are represented as $011_2 \oplus 100_2 \oplus 101_2 = 010_2$ , thus the answer is 2.
$\oplus$ is the bitwise xor operation. To define $x \oplus y$ , consider binary representations of integers $x$ and $y$ . We put the $i$ -th bit of the result to be 1 when exactly one of the $i$ -th bits of $x$ and $y$ is 1. Otherwise, the $i$ -th bit of the result is put to be 0. For example, $0101_2 \, \oplus \, 0011_2 = 0110_2$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted