#abc365e. E - Xor Sigma Problem

E - Xor Sigma Problem

Score : 450450 points

问题陈述

给定一个长度为 NN 的整数序列 A=(A1,,AN)A=(A_1,\ldots,A_N)。找出以下表达式的值:

$\displaystyle \sum_{i=1}^{N-1}\sum_{j=i+1}^N (A_i \oplus A_{i+1}\oplus \ldots \oplus A_j)$。

关于按位异或的说明:非负整数 AABB 的按位异或,记作 ABA \oplus B,定义如下:

  • ABA \oplus B 的二进制表示中,2k2^kk0k \geq 0)位置的数字是 11 当且仅当在 AABB 的二进制表示中 2k2^k 位置的数字中恰好有一个是 11;否则,它是 00

例如,35=63 \oplus 5 = 6(二进制:011101=110011 \oplus 101 = 110)。 一般来说,kk 个整数 p1,,pkp_1, \dots, p_k 的按位异或定义为 $(\cdots ((p_1 \oplus p_2) \oplus p_3) \oplus \cdots \oplus p_k)$。可以证明这与 p1,,pkp_1, \dots, p_k 的顺序无关。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given an integer sequence A=(A1,,AN)A=(A_1,\ldots,A_N) of length NN. Find the value of the following expression:

$\displaystyle \sum_{i=1}^{N-1}\sum_{j=i+1}^N (A_i \oplus A_{i+1}\oplus \ldots \oplus A_j)$.

Notes on bitwise XOR The bitwise XOR of non-negative integers AA and BB, denoted as ABA \oplus B, is defined as follows:

  • In the binary representation of ABA \oplus B, the digit at the 2k2^k (k0k \geq 0) position is 11 if and only if exactly one of the digits at the 2k2^k position in the binary representations of AA and BB is 11; otherwise, it is 00.

For example, 35=63 \oplus 5 = 6 (in binary: 011101=110011 \oplus 101 = 110).
In general, the bitwise XOR of kk integers p1,,pkp_1, \dots, p_k is defined as $(\cdots ((p_1 \oplus p_2) \oplus p_3) \oplus \cdots \oplus p_k)$. It can be proved that this is independent of the order of p1,,pkp_1, \dots, p_k.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1Ai1081 \leq A_i \leq 10^8
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \ldots ANA_{N}

Output

Print the answer.

Sample Input 1

3
1 3 2

Sample Output 1

3

A1A2=2A_1 \oplus A_2 = 2, A1A2A3=0A_1 \oplus A_2 \oplus A_3 = 0, and A2A3=1A_2 \oplus A_3 = 1, so the answer is 2+0+1=32 + 0 + 1 = 3.

Sample Input 2

7
2 5 6 5 2 1 7

Sample Output 2

83