QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 512 MB 总分: 100 可 Hack ✓

#15320. 宝石箱

统计

Noir 有 $n$ 个宝石。第 $i$ 个宝石上写有一个正整数 $a_i$。Noir 想要将这些宝石分成若干个非空的组。每个宝石恰好属于一个组。

假设第 $i$ 个组包含编号为 $k_{i,1}, k_{i,2}, \dots, k_{i,p}$ 的宝石,那么 Noir 将第 $i$ 个组的亮度视为 $a_{k_{i,1}} \oplus a_{k_{i,2}} \oplus \dots \oplus a_{k_{i,p}}$,其中 $\oplus$ 是按位异或(XOR)运算。记第 $i$ 个组的亮度为 $B_i$。

对于一个包含 $m$ 个组的分组方案,Noir 将该方案的价值视为 $B_1 \& B_2 \& \dots \& B_m$,其中 $\&$ 是按位与(AND)运算。

Noir 想要找到所有分组方案中可能的最大价值。

输入格式

输入包含多个测试用例。输入的第一行包含一个整数 $T$ ($1 \le T \le 10^4$),表示测试用例的数量。

对于每个测试用例: 第一行包含一个整数 $n$ ($1 \le n \le 5 \times 10^5$),表示宝石的数量。 第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i < 2^{60}$),表示写在宝石上的整数。

保证所有测试用例中 $n$ 的总和不超过 $5 \times 10^5$。

输出格式

对于每个测试用例,输出一个整数,表示所有分组方案中可能的最大价值。

样例

输入 1

4
4
1 2 3 1
6
4 7 5 2 6 3
4
14 15 9 18
2
251508091405 13011908091815

输出 1

2
6
26
13121614001578

说明

对于第一个测试用例,一种可能的分组方案是 $[1, 2, 3, 1] = [1, 3], [2, 1]$,其价值为 $B_1 \& B_2 = (1 \oplus 3) \& (2 \oplus 1) = 2 \& 3 = 2$。另一种可能的分组方案是 $[1, 2, 3, 1] = [1, 2, 3, 1]$,其价值较低,为 $B_1 = 1 \oplus 2 \oplus 3 \oplus 1 = 1$。可以证明,无法获得大于 2 的价值。

对于第二个测试用例,最佳分组方案是 $[4, 7, 5, 2, 6, 3] = [7], [5, 3], [6], [4, 2]$,其价值为 $7 \& (5 \oplus 3) \& 6 \& (4 \oplus 2) = 6$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.