Universal Cup Judging System

Universal Cup

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100 Difficulty: [show] Hackable ✓
Statistics

長さ $n$ の非負整数列 $A=a_1,a_2,\ldots,a_n$ が与えられます。次のように定義します。

$$F(A)=\max_{1\le k<n}((a_1\mathbin{\&}a_2\mathbin{\&}\cdots\mathbin{\&}a_k)+(a_{k+1}\mathbin{\&}a_{k+2}\mathbin{\&}\cdots\mathbin{\&}a_n)).$$

ここで、$\&$ はビット単位の AND 演算子です。

交換操作を高々 1 回行うことができます。$1\le i<j\le n$ を満たす 2 つの添字 $i$, $j$ を選び、$a_i$ と $a_j$ の値を交換します。

交換操作を高々 1 回行った後の $F(A)$ の取り得る最大値を求めてください。

入力

複数のテストケースがあります。入力の最初の行には、テストケースの個数を表す整数 $T$ が含まれます。各テストケースは以下のとおりです。

最初の行には、数列 $A$ の長さを表す整数 $n$ ($2\le n\le 10^5$) が含まれます。

2 行目には、与えられた数列 $A$ を表す $n$ 個の整数 $a_1,a_2,\cdots,a_n$ ($0\le a_i\le 10^9$) が含まれます。

すべてのテストケースにわたる $n$ の総和は $10^5$ 以下であることが保証されます。

出力

各テストケースについて、交換操作を高々 1 回行った後の $F(A)$ の取り得る最大値を表す整数を 1 行に 1 つ出力してください。

入出力例

入力 1

3
6
6 5 4 3 5 6
6
1 2 1 1 2 2
5
1 1 2 2 2

出力 1

7
3
3

注記

最初のサンプルのテストケースでは、$a_4$ と $a_6$ を交換すると数列は $\{6,5,4,6,5,3\}$ になります。その後 $k=5$ を選ぶと、$F(A)=(6\mathbin{\&}5\mathbin{\&}4\mathbin{\&}6\mathbin{\&}5)+(3)=7$ となります。

2 番目のサンプルのテストケースでは、$a_2$ と $a_4$ を交換すると数列は $\{1,1,1,2,2,2\}$ になります。その後 $k=3$ を選ぶと、$F(A)=(1\mathbin{\&}1\mathbin{\&}1)+(2\mathbin{\&}2\mathbin{\&}2)=3$ となります。

3 番目のサンプルのテストケースでは、交換操作を行いません。$k=2$ を選ぶと、$F(A)=(1\mathbin{\&}1)+(2\mathbin{\&}2\mathbin{\&}2)=3$ となります。

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.