请问我的思路有问题吗?还是代码写错了
#include<bits/stdc++.h>
using namespace std;
const int M=500005;
int n,m,q;
int op[M];
struct SegmentTree{
int l,r,up,down,val;
}t[M*4];
SegmentTree pushup(SegmentTree a,SegmentTree b){
SegmentTree end;
end.l=a.l;
end.r=b.r;
end.up=a.up+max(b.up-a.down,0);
end.down=b.down+max(a.down-b.up,0);
end.val=((a.val>>b.up)<<b.down)|b.val;
return end;
}
void build(int now,int l,int r){
t[now].l=l,t[now].r=r;
if(l==r){
if(op[l]==1){
t[now].down=1;
}
else if(op[l]==2){
t[now].down=1;
t[now].val=1;
}
else{
t[now].up=1;
}
return;
}
int mid=(l+r)>>1;
build(now<<1,l,mid);
build(now<<1|1,mid+1,r);
t[now]=pushup(t[now<<1],t[now<<1|1]);
}
void change(int now,int x,int y){
if(t[now].l==t[now].r){
if(y==1){
t[now].down=1;
t[now].up=0;
t[now].val=0;
}
else if(y==2){
t[now].down=1;
t[now].val=1;
t[now].up=0;
}
else{
t[now].up=1;
t[now].down=0;
t[now].val=0;
}
return;
}
int mid=(t[now].l+t[now].r)>>1;
if(x<=mid) change(now<<1,x,y);
else change(now<<1|1,x,y);
t[now]=pushup(t[now<<1],t[now<<1|1]);
}
SegmentTree ask(int now,int x,int y){
if(x<=t[now].l&&t[now].r<=y){
return t[now];
}
int mid=(t[now].r+t[now].l)>>1;
if(x<=mid&&y>mid){
SegmentTree end,a=t[now<<1],b=t[now<<1|1];
end.l=a.l;
end.r=b.r;
end.up=a.up+max(b.up-a.down,0);
end.down=b.down+max(a.down-b.up,0);
end.val=((a.val>>b.up)<<b.down)|b.val;
return end;
}
if(x<=mid) return ask(now<<1,x,y);
if(y>mid) return ask(now<<1|1,x,y);
}
int main(){
cin>>n>>m>>q;
for(int i=1;i<=m;i++){
cin>>op[i];
}
build(1,1,m);
while(q--){
int tp,s,l,r;
cin>>tp;
if(tp==1){
cin>>s>>l>>r;
SegmentTree ans=ask(1,l,r);
cout<<(((s>>ans.up)<<ans.down)|ans.val)<<endl;
}
else{
cin>>l>>r;
change(1,l,r);
}
}
return 0;
}