CF2268C.KiaKio and Energy Intervals

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Kia and Kio found a glowing array a1,a2,…,ana_1, a_2, \ldots, a_n 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 ll and rr with l<rl \lt 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)m = \max\left(a_l, a_{l+1}, \ldots, a_r\right), and the terminal masks every element of the segment with mm (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)(l, r), what is the largest energy the terminal can produce?

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

Kia 和 Kio 在一座古老数字王国的废墟中,一个水晶终端内发现了一个发着微光的数组 a1,a2,…,ana_1, a_2, \ldots, a_n。

该终端的工作方式如下:Kia 选择数组的一个子段,即任意两个下标 ll 和 rr,满足 l<rl \lt r(因此该子段至少包含两个元素);Kio 则找出该子段中的最强能量值,即 m=max⁡(al,al+1,…,ar)m = \max\left(a_l, a_{l+1}, \ldots, a_r\right),随后终端对该子段中每个元素执行与 mm 的按位与(bitwise AND)操作,并将所有结果进行按位异或(bitwise XOR)融合:

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

该数值即为释放的能量值。

Kia 希望获得尽可能强的能量爆发。在所有合法子段 (l,r)(l, r) 中,终端所能产生的最大能量值是多少?

此处,&\& 表示按位与运算,⊕\oplus 表示按位异或运算。

输入格式

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

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

The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (0≤ai<2180 \le a_i \lt 2^{18}).

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

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052 \le n \le 2\cdot10^5)—— 表示数组的大小。

第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(0≤ai<2180 \le a_i \lt 2^{18})。

保证所有测试用例的 nn 之和不超过 2⋅1052\cdot10^5。

输出格式

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)(l,r) satisfying l<rl \lt r.

对于每个测试用例,输出一个整数——即在所有满足 l<rl \lt 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=1l=1 and r=2r=2. The maximum element in this interval is m=7m=7.

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

在第一个测试用例中,一个最优区间是 l=1l=1 和 r=2r=2。该区间内的最大元素为 m=7m=7。

其值为 (1 & 7)⊕(7 & 7)=6(1\,\& \,7)\oplus(7\,\&\,7) = 6。

输入解题思路,AI测评打分。不知道怎么写?

首页