The minions have finally found their new master. This time, he is a Math professor and he is trying veryhard to teach them math. He has been teaching them bitwise operators for over a year! They learnt aboutAND(&) and OR (|) operators and it is time for a quiz to test them.
The quiz is very simple, they will be given a number A of AND(&) operators, a number B of OR (|)operators and (A + B + 1) integers. They have to find the maximum number that can be obtained byinserting the & and | operators between the given nonnegative integers without changing their order.
Finally, there is a special requirement for this quiz, they are required to evaluate the operators from leftto right.
Input
The first line of the input will be a single integer T, the number of test cases (1 ≤ T ≤ 100), followedby T test cases.Each test case will consist of 2 lines. The first line will contain 2 integers A and B (0 ≤ A, B ≤ 10, 000)representing the number of AND(&) and OR (|) operators, respectively. The second line of input willconsist of (A + B + 1) 64-bit nonnegative integers separated by single spaces.
Output
For each test case, output a single line containing the maximum number that can be obtained by insertingthe operators between the given integers.
样例输入复制
2 1 1 1 4 5 2 2 2 3 11 4 5
样例输出复制
5 7
题意:
在a + b + 1个数之间插入 a 个 & 号和 b 个 | 号,问可以得到的最大值
题解:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e4 +10;
int p[N];
int main()
{
int n, t, a, b;
scanf("%d", &t);
while(t--)
{
scanf("%d%d", &a, &b);
n = a + b + 1;
for(int i = 1; i <= n; ++i)
{
scanf("%d", &p[i]);
}
ll ans = p[1];
for(int i = 2; i <= n; ++i)
{
if(a)
{
ans &= p[i];
a--;
}
else
{
ans |= p[i];
}
}
cout<<ans<<'\n';
}
return 0;
}