WorldQuant Round 1 (Codeforces Round 1128, Div. 1 + Div. 2)
G
1 2 3 and XOR, Where Did Everybody Go?
Codeforces
2800
原题
← F2H →
翻译中…

You are given a sequence $a$ consisting of $n$ non-negative integers.

翻译中…

Given a sequence $b$ consisting of $k$ non-negative integers, define a dot increment on $b$ as the following operation:

翻译中…
  • Select an index $i$ ($1 \le i \le k$), and add any non-negative integer of choice to $b_i$.
翻译中…

Then, let $f(b)$ be the minimum value of $b_1 \oplus b_2 \oplus \ldots \oplus b_k$ after performing a dot increment on $b$ exactly once.$^{\text{∗}}$

翻译中…

Please find the value of the following sum.

翻译中…

$$\sum_{1 \le l \le r \le n}f([a_l,a_{l+1},\ldots,a_r])$$

翻译中…

$^{\text{∗}}$Here, $\oplus$ denotes the bitwise XOR operation.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains an integer $n$ ($1 \le n \le 4\cdot 10^5$).

翻译中…

The second line of each test case contains integers $a_1,a_2,\ldots,a_n$ ($0 \le a_i \lt 2^{25}$).

翻译中…

It is guaranteed that the sum of $n$ does not exceed $4\cdot 10^5$ over all test cases.

翻译中…

Output

翻译中…

For each test case, output the answer to the problem on a separate line.

翻译中…

Note

翻译中…

In the first test case, for example, consider $f([5,4,6,7,5])$

翻译中…

By incrementing $b_2=4$ by $1$, $b$ becomes $[5,5,6,7,5]$, and $5 \oplus 5 \oplus 6 \oplus 7 \oplus 5 = 4$.

翻译中…

It can be shown that $b_1 \oplus b_2 \oplus b_3 \oplus b_4 \oplus b_5$ cannot be smaller than $4$ after one dot increment.

翻译中…

The sum of minimum values over all subarrays can be shown to be $43$.

翻译中…

样例

Input #1
4
5
5 4 6 7 5
5
3 3 2 2 3
1
67
10
1827481 5921082 14619611 643973 6718274 2948 244716 29 0 6717827
Output #1
43
21
67
36695941
InputCopy OutputCopy
题目信息
题号
2261G
时间限制
7 s
内存限制
1024 MB
标签
位运算
数据结构
分治
动态规划
贪心
排序
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。