QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#15320. Gemcrate

Statistics

Noir は $n$ 個の宝石を持っています。$i$ 番目の宝石には正の整数 $a_i$ が書かれています。Noir はこれらの宝石をいくつかの空でないグループに分けたいと考えています。各宝石はちょうど $1$ つのグループに属します。

$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 は、すべてのグループ分けの方法における価値の最大値を求めたいと考えています。

入力

入力は複数のテストケースを含みます。入力の $1$ 行目には、テストケースの個数を表す整数 $T$($1 \le T \le 10^4$)が含まれます。

各テストケースについて、$1$ 行目には宝石の個数を表す整数 $n$($1 \le n \le 5 \times 10^5$)が含まれます。

$2$ 行目には、宝石に書かれた整数を表す $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$ つ目のテストケースでは、可能なグループ分けの方法の $1$ つは $[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$ より大きい価値を達成することは不可能であることが証明できます。

$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.