#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
int a[N], b[N];
signed main() {
int T;
cin >> T;
while (T --) {
int n;
cin >> n;
for (int i = 1; i <= n; i ++)
cin >> a[i];
for (int i = 1; i <= n; i ++)
cin >> b[i];
int ans = 0;
for (int i = 30; ~i; i --) {
ans ^= (1 << i);
map <int, int> _1, _2;
for (int j = 1; j <= n; j ++)
_1[a[j] & ans] ++;
for (int j = 1; j <= n; j ++)
_2[b[j] & ans] ++;
for (int j = 1; j <= n; j ++)
if (_1[a[j] & ans] != _2[(a[j] & ans) ^ ans]) {
ans ^= (1 << i);
break;
}
}
cout << ans << '\n';
}
return 0;
}
CodeForces 1721D【贪心】【位运算】
最新推荐文章于 2022-08-30 19:27:06 发布