画一画图就能知道规律
倘若询问区间是偶数
画图可知,答案为零
为奇数,则为
(A_L)^(A_{L+2})·······(A_R)
然后奇数偶数分别开一个 树状数组
就行了
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,q;
long long k;
long long ans;
long long l,r;
long long tree[200001][2];
long long a[200001];
long long lowbit(long long x){
return x&-x;
}
long long find(long long x,long long f){
long long ans=0;
while(x){
ans^=tree[x][f];
x-=lowbit(x);
}
return ans;
}
void up(long long x,long long y,long long f){
while(x<=n){
tree[x][f]^=y;
x+=lowbit(x);
}
return ;
}
long long x;
int main(){
scanf("%lld%lld",&n,&q);
for(long long i=1;i<=n;++i){
scanf("%lld",&a[i]);
if(i%2){
up(i,a[i],1);
}else{
up(i,a[i],0);
}
}
for(long long i=1;i<=q;++i){
scanf("%lld%lld%lld",&k,&l,&r);
if(k==1)
if(l%2){
up(l,a[l]^r,1);// 因为是异或
//所以说这样可以抵消原来的数 a[l]
a[l]=r;
}else{
up(l,a[l]^r,0);
a[l]=r;
}
if(k==2){
if((r-l+1)%2){
if(l%2){
printf("%lld
",find(r,1)^find(l-1,1)) ;
}else{
printf("%lld
",find(r,0)^find(l-1,0)) ;
}
}else{
cout<<0<<endl;
}
}
}
return 0;
}