依据异或特性,如果n为偶数,单调递减:与b[i]|越多越小
反之递增
点击查看代码
#include<bits/stdc++.h>
using namespace std;
const int N=2e5 + 10;
#define LL long long
int a[N], b[N];
void solve() {
int n, m;
cin >> n >> m;
if (n % 2 == 0) {
int mn = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mn ^= a[i];
}
LL w = 0;
for (int i = 1; i <= m; i++) {
int x;
cin >> x;
w |= x;
}
int mx = 0;
for (int i = 1; i <= n; i++) {
mx ^= a[i] | w;
}
cout << mx<<' '<<mn;
}
else {
int mn = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mn ^= a[i];
}
cout << mn << ' ';
LL w = 0;
for (int i = 1; i <= m; i++) {
int x;
cin >> x;
w |= x;
}
int mx = 0;
for (int i = 1; i <= n; i++) {
mx ^= a[i] | w;
}
cout << mx;
}
cout << '\n';
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}