样例输入
10 10
15 3 1 12 5 8 8 15 9 14
3 4 36
1 9 10
1 2 10
2 6 7 3
2 1 6 15
3 7 68
3 10 43
3 2 34
1 3 5
2 3 4 11
样例输出
0
32
43
#include<stdio.h>
#include<algorithm>
using namespace std;
const int N=1e5+50;
int s[N],a[N];
struct tree {
int l,r,dat,add;
} t[N*4],ts[N*4];
int solve(int x) {
int ans=0;
while(x) {
if(x&1)ans++;
x>>=1;
}
return ans%2;
}
void build(int l,int r,int p) {
t[p].l=l,t[p].r=r;
if(l==r) {
t[p].dat=s[l]*a[l];
ts[p].dat=s[l];
return;
}
int mid=(l+r)/2;
build(l,mid,p*2);
build(mid+1,r,p*2+1);
t[p].dat=t[p*2].dat^t[p*2+1].dat;
ts[p].dat=ts[p*2].dat+ts[p*2+1].dat;
}
void spread(int p) {
if(t[p].add) {
if(ts[p*2].dat%2) {
t[p*2].dat=t[p*2].dat^t[p].add;
}
if(ts[p*2+1].dat%2) {
t[p*2+1].dat=t[p*2+1].dat^t[p].add;
}
t[p*2].add^=t[p].add;
t[p*2+1].add^=t[p].add;
t[p].add=0;
}
}
void change1(int p,int x,int v) {
if(t[p].l==t[p].r) {
a[t[p].l]=v;
t[p].dat=a[t[p].l]*s[t[p].l];
return;
}
spread(p);
int mid=(t[p].l+t[p].r)/2;
if(x<=mid)change1(p*2,x,v);
else change1(p*2+1,x,v);
t[p].dat=t[p*2].dat^t[p*2+1].dat;
}
void change2(int p,int l,int r,int d) {
if(l<=t[p].l&&t[p].r<=r) {
if(ts[p].dat%2) {
t[p].dat=t[p].dat^d;
}
t[p].add^=d;
return;
}
spread(p);
int mid=(t[p].l+t[p].r)/2;
if(l<=mid)change2(p*2,l,r,d);
if(r>mid)change2(p*2+1,l,r,d);
t[p].dat=t[p*2].dat^t[p*2+1].dat;
}
int ask(int p,int l,int r) {
if(l<=t[p].l&&t[p].r<=r) {
return t[p].dat;
}
spread(p);
int mid=(t[p].l+t[p].r)/2;
int ans=0;
if(l<=mid)ans=ans^ask(p*2,l,r);
if(r>mid)ans=ans^ask(p*2+1,l,r);
return ans;
}
int main() {
int n,q;
scanf("%d %d",&n,&q);
for(int i=1; i<=n; ++i) {
s[i]=solve(i);
}
for(int i=1; i<=n; ++i) {
scanf("%d",&a[i]);
}
build(1,n,1);
while(q--) {
int x,l,r;
scanf("%d %d %d",&x,&l,&r);
if(x==1) {
printf("%d\n",ask(1,l,r));
} else if(x==2) {
int sum;
scanf("%d",&sum);
change2(1,l,r,sum);
} else {
change1(1,l,r);
}
}
return 0;
}