#P3760. [TJOI2017] 异或和

    ID: 1372 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2017各省省选树状数组进制前缀和天津

[TJOI2017] 异或和

Description

Xiao Ming from Garidon High School has recently fallen in love with math contests. Many problems are related to the sums of contiguous segments of a sequence. For a sequence, computing all of its contiguous sums (i.e., subarray sums) is very easy for Xiao Ming.

But today he encountered a tougher problem: not only do you need to quickly obtain all subarray sums, you also need to quickly compute the XOR of these sums.

Xiao Ming has already computed all subarray sums. However, without telling you these sums, he challenges you to quickly compute the XOR of all subarray sums of the sequence.

Input Format

The first line contains an integer nn, indicating the length of the sequence.

The second line contains nn non-negative integers a1,a2ana_1, a_2 \dots a_n representing the sequence.

Output Format

Output the XOR of all subarray sums of the sequence.

3
1 2 3
0

Hint

Sample Explanation:

The sequence [1, 2, 3] has 6 subarray sums: 1, 2, 3, 3, 5, 6, and $1 \text{ xor } 2 \text{ xor } 3 \text{ xor } 3 \text{ xor } 5 \text{ xor } 6 = 0$.

Constraints:

  • For 20%20\% of the testdata, 1n1001 \le n \le 100.
  • For 100%100\% of the testdata, 1n1051 \le n \le 10^5, ai106\sum a_i \le 10^6.

Translated by ChatGPT 5