第 1124 场 Codeforces Round(Div. 1)
C
KiaKio 与能量区间
KiaKio and Energy Intervals
Codeforces
2300
原题
← BD →

KiaKio 与能量区间AI (CI翻译)

Kia and Kio found a glowing array $a_1, a_2, \ldots, a_n$ inside a crystal terminal in the ruins of an ancient digital kingdom.

Kia 和 Kio 在古老数字王国的废墟中,发现了一台水晶终端,里面有一个发光数组 $a_1, a_2, \ldots, a_n$。AI (CI翻译)

The terminal works like this. Kia picks a segment of the array: any two indices $l$ and $r$ with $l \lt r$ (so the segment always has at least two elements). Kio then finds the strongest energy in that segment, $m = \max\left(a_l, a_{l+1}, \ldots, a_r\right)$, and the terminal masks every element of the segment with $m$ (bitwise AND), then fuses the results together (bitwise XOR):

这台终端的工作方式如下:Kia 选择数组中的一个区间,即任意两个满足 $l \lt r$ 的下标 $l$ 和 $r$(因此区间至少包含两个元素)。随后,Kio 找出该区间中的最强能量 $m = \max\left(a_l, a_{l+1}, \ldots, a_r\right)$。终端将区间内的每个元素都与 $m$ 进行按位 AND 运算,然后将结果按位 XOR 合并:AI (CI翻译)

$$ (a_l \,\&\, m)\oplus(a_{l+1} \,\&\, m)\oplus\cdots\oplus(a_r \,\&\, m). $$

$$ (a_l \,\&\, m)\oplus(a_{l+1} \,\&\, m)\oplus\cdots\oplus(a_r \,\&\, m). $$AI (CI翻译)

That number is the energy released.

这个数就是释放出的能量。AI (CI翻译)

Kia wants the strongest possible blast. Over all valid segments $(l, r)$, what is the largest energy the terminal can produce?

Kia 想要制造尽可能强的爆发。在所有合法区间 $(l, r)$ 中,终端能够产生的最大能量是多少?AI (CI翻译)

Here, $\&$ denotes the bitwise AND operation, and $\oplus$ denotes the bitwise XOR operation.

这里,$\&$ 表示按位 AND 运算,$\oplus$ 表示按位 XOR 运算。AI (CI翻译)

Input

输入格式

AI (CI翻译)

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.

每个输入包含多组测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)

The first line of each test case contains a single integer $n$ ($2 \le n \le 2\cdot10^5$) — the size of the array.

每个测试用例的第一行包含一个整数 $n$($2 \le n \le 2\cdot10^5$)——数组的长度。AI (CI翻译)

The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0 \le a_i \lt 2^{18}$).

第二行包含 $n$ 个整数 $a_1,a_2,\ldots,a_n$($0 \le a_i \lt 2^{18}$)。AI (CI翻译)

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

保证所有测试用例的 $n$ 之和不超过 $2\cdot10^5$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, print a single integer — the maximum possible value of

对于每个测试用例,输出一个整数——在所有满足 $l \lt r$ 的数对 $(l,r)$ 中,表达式AI (CI翻译)

$$ (a_l \,\&\, m)\oplus(a_{l+1} \,\&\, m)\oplus\cdots\oplus(a_r \,\&\, m) $$

$$ (a_l \,\&\, m)\oplus(a_{l+1} \,\&\, m)\oplus\cdots\oplus(a_r \,\&\, m) $$AI (CI翻译)

among all pairs $(l,r)$ satisfying $l \lt r$.

能够取得的最大值。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first test case, one optimal interval is $l=1$ and $r=2$. The maximum element in this interval is $m=7$.

在第一个测试用例中,一个最优区间是 $l=1$、$r=2$。该区间中的最大元素为 $m=7$。AI (CI翻译)

The value becomes $(1\,\& \,7)\oplus(7\,\&\,7) = 6$.

计算结果为 $(1\,\& \,7)\oplus(7\,\&\,7) = 6$。AI (CI翻译)

样例

Input #1
4
5
1 7 3 7 2
3
3 1 2
5
1 5 2 3 4
4
3 5 2 6
Output #1
6
2
5
5
InputCopy OutputCopy
题目信息
题号
2268C
时间限制
2 s
内存限制
256 MB
标签
二分
位运算
数据结构
分治
并查集
贪心
树
双指针

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