atcoder092(中)ARC092 D - Two Sequences

【题意】给定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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值