#P9236. [蓝桥杯 2023 省 A] 异或和之和

[蓝桥杯 2023 省 A] 异或和之和

Problem Description

Given an array AiA_i, compute the XOR sum of every subarray and then sum up all these XOR sums. In other words, for every pair L,RL, R satisfying 1LRn1 \leq L \leq R \leq n, compute the XOR of the elements from the LL-th to the RR-th in the array, and output the total sum of the results over all such L,RL, R.

Input Format

The first line contains an integer nn.

The second line contains nn integers AiA_i, separated by a single space.

Output Format

Output one line containing an integer representing the answer.

5
1 2 3 4 5
39

Hint

Constraints

For 30%30\% of the testdata, n300n \leq 300.

For 60%60\% of the testdata, n5000n \leq 5000.

For all testdata, 1n1051 \leq n \leq 10^5, 0Ai2200 \leq A_i \leq 2^{20}.

Translated by ChatGPT 5