#P9696. [GDCPC 2023] Swapping Operation
[GDCPC 2023] Swapping Operation
题目描述
Given a non-negative integer sequence of length , define
$$F(A)=\max\limits_{1\leq k<n} ((a_1 \,\&\, a_2 \,\&\, \cdots \,\&\, a_k)+(a_{k+1} \,\&\, a_{k+2} \,\&\, \cdots \,\&\, a_n)) $$where is the bitwise-and operator.
You can perform the swapping operation at most once: choose two indices and such that and then swap the values of and .
Calculate the maximum possible value of after performing at most one swapping operation.
输入格式
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first line contains an integer () indicating the length of sequence .
The second line contains integers () indicating the given sequence .
It's guaranteed that the sum of of all test cases will not exceed .
输出格式
For each test case output one line containing one integer indicating the maximum possible value of after performing at most one swapping operation.
3
6
6 5 4 3 5 6
6
1 2 1 1 2 2
5
1 1 2 2 2
7
3
3
提示
For the first sample test case, we can swap and so the sequence becomes . We can then choose so that $F(A) = (6 \,\&\, 5 \,\&\, 4 \,\&\, 6 \,\&\, 5) + (3) = 7$.
For the second sample test case, we can swap and so the sequence becomes . We can then choose so that $F(A) = (1 \,\&\, 1 \,\&\, 1) + (2 \,\&\, 2 \,\&\, 2) = 3$.
For the third sample test case we do not perform the swapping operation. We can then choose so that .