RT 把query函数中的所有‘ ^ ’换成 ‘ - ’,竟然过了样例????谁能告诉我怎么回事,我就是因为这个爆了一次琳。。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(x) x&(-x)
ll n,m,a[100002],b[200002],c[100002],z,y;
ll g(ll x){
ll ans=0,k=x;
for(;x;x-=lowbit(x))ans^=a[x];
return ans;
}
ll g2(ll x){
ll ans=0,k=x;
for(;x;x-=lowbit(x))ans^=c[x];
return ans;
}
void f(ll x,ll k){
for(int i=x;i<=y;i+=lowbit(i))a[i]^=k;
}
void f2(ll x,ll k){
for(int i=x;i<=z;i+=lowbit(i))c[i]^=k;
}
ll query(ll l,ll r){
// if(l==r)return 0;
ll ans=0,p=r-l+1,s=(p+1)/2,po=l+s-1;
if(p%2){
if(l%2==0){
return g((r+1)/2)^g((l+1)/2-1);
}else{
return g2((r+1)/2)^g2((l+1)/2-1);
}
}
return ans;
}
int main(){
ll s=0;
for(ll i=(cin>>n>>m,1),x=(z=(n+1)/2,y=n-z);i<=n;i++){
scanf("%lld",&b[i]);
if(i%2==0)f((i+1)/2,b[i]);
if(i%2)f2((i+1)/2,b[i]);
s=x;
}
for(ll i=1,op,k,s;i<=m;i++){
scanf("%lld%lld%lld",&op,&k,&s);
if((op)==1){
if(k%2==0)f((k+1)/2,b[k]^s);
if(k%2)f2((k+1)/2,b[k]^s);
b[k]=s;
}else cout<<query(k,s)<<endl;
}
}