【题意】给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n)。n<=200000。
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
//#include<queue>
//#include<time.h>
//#include<complex>
#include<algorithm>
#include<stdlib.h>
using namespace std;
int n;
#define maxn 200011
int a[maxn], b[maxn], na[maxn], nb[maxn];
int main()
{
scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
int ans = 0;
for (int i = 0; i <= 28; i++)
{
for (int j = 1; j <= n; j++)
na[j] = a[j] & ((1 << (i + 1)) - 1), nb[j] = b[j] & ((1 << (i + 1)) - 1);
sort(nb + 1, nb + 1 + n);
int t1 = 1 << i, t2 = 2 * t1, t3 = 3 * t1, t4 = 4 * t1;
int now = 0;
for (int j = 1; j <= n; j++)
{
now ^= (lower_bound(nb + 1, nb + 1 + n, t2 - na[j]) - lower_bound(nb + 1, nb + 1 + n, t1 - na[j])) & 1;
now ^= (lower_bound(nb + 1, nb + 1 + n, t4 - na[j]) - lower_bound(nb + 1, nb + 1 + n, t3 - na[j])) & 1;
}
ans |= now << i;
}
printf("%d\n", ans);
return 0;
}