QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 512 MB 満点: 100 ハック可能 ✓

#15320. Gemcrate

統計

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$ 為位元互斥或(bitwise-XOR)運算。將第 $i$ 個組別的亮度記為 $B_i$。

對於一個分成 $m$ 個組別的分組方式,Noir 將此分組方式的價值視為 $B_1 \& B_2 \& \dots \& B_m$,其中 $\&$ 為位元且(bitwise-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.