QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 512 MB Points totaux : 100 Hackable ✓

#15320. Gemcrate

Statistiques

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 \cdots \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, \cdots, a_n$($1 \le a_i < 2^{60}$),代表寫喺寶石上面嘅整數。

保證所有測試資料入面 $n$ 嘅總和唔超過 $5 \times 10^5$。

輸出格式

對於每組測試資料,輸出一個整數,代表喺所有分組方案入面可能達到嘅最大價值。

範例

4
4
1 2 3 1
6
4 7 5 2 6 3
4
14 15 9 18
2
251508091405 13011908091815
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.