CF1322B.Present

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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)oplusldotsoplus(a_1+a_n)oplus(a_2+a_3)oplusldotsoplus(a_2+a_n)ldotsoplus(a_n−1+a_n)(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) \\\\

Here x⊕yx \oplus y is a bitwise XOR operation (i.e. xx ^ yy in many modern programming languages). You can read about it in Wikipedia: https://en.wikipedia.org/wiki/Exclusive_or#Bitwise_operation.

凯瑟琳在三八妇女节收到了一个整数数组作为礼物。后来她对此感到厌倦,便开始计算该数组的各种“无用”性质,并且对之前想到的每一种性质都成功地完成了计算。但当她想到另一种性质——数组中所有元素两两之和的异或值时,她意识到对于非常大的数组,自己无法完成计算,因此向你求助。你能帮她解决这个问题吗?形式化地说,你需要计算:

(a_1+a_2)oplus(a_1+a_3)oplusldotsoplus(a_1+a_n)oplus(a_2+a_3)oplusldotsoplus(a_2+a_n)ldotsoplus(a_n−1+a_n)(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) \\\\

其中 x⊕yx \oplus y 表示按位异或运算(即许多现代编程语言中的 x ^ y)。你可以在维基百科了解该运算:https://en.wikipedia.org/wiki/Exclusive_or#Bitwise_operation。

输入格式

The first line contains a single integer nn (2≤n≤400 0002 \leq n \leq 400\,000) — the number of integers in the array.

The second line contains integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1071 \leq a_i \leq 10^7).

第一行包含一个整数 nn(2≤n≤400 0002 \leq n \leq 400\,000)—— 表示数组中整数的个数。

第二行包含整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1071 \leq a_i \leq 10^7)。

输出格式

Print a single integer — xor of all pairwise sums of integers in the given array.

输出一个整数——给定数组中所有整数两两之和的异或(xor)值。

输入输出样例

  • 输入#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=31 + 2 = 3.

In the second sample case there are three sums: 1+2=31 + 2 = 3, 1+3=41 + 3 = 4, 2+3=52 + 3 = 5. In binary they are represented as 0112⊕1002⊕1012=0102011_2 \oplus 100_2 \oplus 101_2 = 010_2, thus the answer is 2.

⊕\oplus is the bitwise xor operation. To define x⊕yx \oplus y, consider binary representations of integers xx and yy. We put the ii-th bit of the result to be 1 when exactly one of the ii-th bits of xx and yy is 1. Otherwise, the ii-th bit of the result is put to be 0. For example, 01012 ⊕ 00112=011020101_2 \, \oplus \, 0011_2 = 0110_2.

在第一个样例中,只有一种和:1+2=31 + 2 = 3。

在第二个样例中,共有三种和:1+2=31 + 2 = 3、1+3=41 + 3 = 4、2+3=52 + 3 = 5。它们的二进制表示分别为 0112⊕1002⊕1012=0102011_2 \oplus 100_2 \oplus 101_2 = 010_2,因此答案为 2。

⊕\oplus 表示按位异或(bitwise xor)运算。定义 x⊕yx \oplus y 时,考虑整数 xx 和 yy 的二进制表示。当且仅当 xx 和 yy 的第 ii 位中恰好有一个为 1 时,结果的第 ii 位为 1;否则,结果的第 ii 位为 0。例如,01012 ⊕ 00112=011020101_2 \, \oplus \, 0011_2 = 0110_2。

输入解题思路,AI测评打分。不知道怎么写?

首页