c语言 数组 异或,[luogu3760 TJOI2017] 异或和(树状数组)

传送门 ###Solution 一位一位考虑,直接得到答案中第i为是否为1 ###Code

//By Menteur_Hxy

#include

#include

#include

#include

#include

#include

#include

#define Re register

#define Ms(a,b) memset(a,(b),sizeof(a))

#define Fo(i,a,b) for(Re int i=(a),_=(b);i<=_;i++)

#define Ro(i,a,b) for(Re int i=(b),_=(a);i>=_;i--)

#define Lof(i,a,b) for(Re int i=(a),_=(b);i<=_;i+=i&-i)

#define Lor(i,a) for(Re int i=(a);i;i-=i&-i)

using namespace std;

typedef long long LL;

inline int read() {

int x=0,f=1;char c=getchar();

while(!isdigit(c)) {if(c=='-')f=-f;c=getchar();}

while(isdigit(c)) x=(x<<1)+(x<<3)+c-48,c=getchar();

return x*f;

}

const int N=1e6+10;

int n,m;

LL ans;

LL a[N],s[N],b[N];

struct BIT{

int da[2][N];

void clear() {Ms(da,0);}

void Modify(int x,int k) {Lof(i,x,m)da[k][i]++;}

LL query(int x,int k) {LL t=0;Lor(i,x)t+=da[k][i];return t;}

}B;

int main() {

n=read(); Fo(i,1,n) a[i]=read(),s[i]=s[i-1]+a[i]; m=s[n];

Fo(i,0,20) {

if((1ll<m) break;

bool cnt=0; B.clear(); B.Modify(1,0);

Fo(j,1,n) {

LL o=s[j]&(1ll<

if(o) tmp=B.query(b[j]+1,0)+B.query(m,1)-B.query(b[j]+1,1);

else tmp=B.query(b[j]+1,1)+B.query(m,0)-B.query(b[j]+1,0);

if(tmp&1) cnt^=1; B.Modify(b[j]+1,(o>0)); b[j]|=o;

}

if(cnt) ans|=(1ll<

}

printf("%lld",ans);

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值