CF1322B Present

发布时间:2022-07-01 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了CF1322B Present脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

Jinnie

看到莫名其妙的异或题,应该考虑按照位数处理。

这样我们分别考虑每一位的答案,需要先取模。

排序,让序列有了单调性,并且可以观察到,对于第k位只有两个数的和属于

([2^k,2^{k+1}-1]cap[2^{k+1}+2^k,2^{k+2}-2])才行

最后的右边界是什么东西?我们取模了啊. 双指针解决。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<cmath>
#include<stack>
#include<algorithm>
#define int long long
using namespace std;
template<class T>inline void read(T &x)
{
    x=0;register char c=getchar();register bool f=0;
    while(!isdigit(c))f^=c=='-',c=getchar();
    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
    if(f)x=-x;
}
template<class T>inline void print(T x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar('0'+x%10);
}
int n;
int ans;
int a[400005];
int b[400005];
int cal(int L,int R){
	if(L>R) return 0;
	int res=0;
	int l=1;
	int r=1;
	for(int i=n;i>=1;--i){
		while(l<=n&&b[i]+b[l]<L) ++l;
		while(r<=n&&b[i]+b[r]<=R) ++r;
		res+=r-l-(l<=i&&r>i);
	}
	return (res>>1)&1;
}
int deal(int x){
	for(int i=1;i<=n;++i){
		b[i]=(a[i]&((1<<(x+1))-1));
	}
	sort(b+1,b+n+1);
	return cal(1<<x,(1<<(x+1))-1)^cal(3<<x,(1<<(x+2))-2);
}
signed main(){
	read(n);
	for(int i=1;i<=n;++i){
		read(a[i]);
	}
	for(int i=0;i<26;++i){
		ans|=deal(i)<<i;
	}
	cout<<ans;
	return 0;
}

脚本宝典总结

以上是脚本宝典为你收集整理的CF1322B Present全部内容,希望文章能够帮你解决CF1322B Present所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: