Universal Cup Judging System

Universal Cup

Süre Sınırı: 1 s Bellek Sınırı: 1024 MB Toplam puan: 100 Zorluk: [göster] Hack'lenebilir ✓
İstatistikler

길이가 $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\le i<j\le n$을 만족하는 두 인덱스 $i$, $j$를 선택한 다음 $a_i$와 $a_j$의 값을 교환합니다.

교환 연산을 최대 한 번 수행한 후 가능한 $F(A)$의 최댓값을 구하세요.

입력

테스트 케이스는 여러 개입니다. 입력의 첫 번째 줄에는 테스트 케이스의 개수를 나타내는 정수 $T$가 포함됩니다. 각 테스트 케이스는 다음과 같습니다.

첫 번째 줄에는 수열 $A$의 길이를 나타내는 정수 $n$ ($2\le n\le 10^5$)이 포함됩니다.

두 번째 줄에는 주어진 수열 $A$를 나타내는 $n$개의 정수 $a_1,a_2,\cdots,a_n$ ($0\le a_i\le 10^9$)이 포함됩니다.

모든 테스트 케이스의 $n$의 합은 $10^5$을 넘지 않음이 보장됩니다.

출력

각 테스트 케이스마다 교환 연산을 최대 한 번 수행한 후 가능한 $F(A)$의 최댓값을 나타내는 정수 하나를 한 줄에 출력하세요.

예제

입력 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$입니다.

두 번째 예제 테스트 케이스에서는 $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$입니다.

세 번째 예제 테스트 케이스에서는 교환 연산을 수행하지 않습니다. $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.