CF2268C.KiaKio and Energy Intervals
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Kia and Kio found a glowing array a1,a2,…,an inside a crystal terminal in the ruins of an ancient digital kingdom.
The terminal works like this. Kia picks a segment of the array: any two indices l and r with l<r (so the segment always has at least two elements). Kio then finds the strongest energy in that segment, m=max(al,al+1,…,ar), and the terminal masks every element of the segment with m (bitwise AND), then fuses the results together (bitwise XOR):
$ (a_l ,&, m)\oplus(a_{l+1} ,&, m)\oplus\cdots\oplus(a_r ,&, m). $
That number is the energy released.
Kia wants the strongest possible blast. Over all valid segments (l,r), what is the largest energy the terminal can produce?
Here, & denotes the bitwise AND operation, and ⊕ denotes the bitwise XOR operation.
Kia 和 Kio 在一座古老数字王国的废墟中,一个水晶终端内发现了一个发着微光的数组 a1,a2,…,an。
该终端的工作方式如下:Kia 选择数组的一个子段,即任意两个下标 l 和 r,满足 l<r(因此该子段至少包含两个元素);Kio 则找出该子段中的最强能量值,即 m=max(al,al+1,…,ar),随后终端对该子段中每个元素执行与 m 的按位与(bitwise AND)操作,并将所有结果进行按位异或(bitwise XOR)融合:
$ (a_l ,&, m)\oplus(a_{l+1} ,&, m)\oplus\cdots\oplus(a_r ,&, m). $
该数值即为释放的能量值。
Kia 希望获得尽可能强的能量爆发。在所有合法子段 (l,r) 中,终端所能产生的最大能量值是多少?
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains a single integer n (2≤n≤2⋅105) — the size of the array.
The second line contains n integers a1,a2,…,an (0≤ai<218).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(2≤n≤2⋅105)—— 表示数组的大小。
第二行包含 n 个整数 a1,a2,…,an(0≤ai<218)。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, print a single integer — the maximum possible value of
$ (a_l ,&, m)\oplus(a_{l+1} ,&, m)\oplus\cdots\oplus(a_r ,&, m) $
among all pairs (l,r) satisfying l<r.
对于每个测试用例,输出一个整数——即在所有满足 l<r 的数对 (l,r) 中,表达式
$ (a_l ,&, m)\oplus(a_{l+1} ,&, m)\oplus\cdots\oplus(a_r ,&, m) $
所能取得的最大值。
输入输出样例
输入#1
4 5 1 7 3 7 2 3 3 1 2 5 1 5 2 3 4 4 3 5 2 6
输出#1
6 2 5 5
说明/提示
In the first test case, one optimal interval is l=1 and r=2. The maximum element in this interval is m=7.
The value becomes (1&7)⊕(7&7)=6.
在第一个测试用例中,一个最优区间是 l=1 和 r=2。该区间内的最大元素为 m=7。
其值为 (1&7)⊕(7&7)=6。
输入解题思路,AI测评打分。不知道怎么写?