zhang20091227 @ 2024-11-12 17:31:58
#include<bits/stdc++.h>
#define left(x) (x)<<1
#define int long long
#define right(x) (x)<<1|1
using namespace std;
int const N=(1e6+1)*4;
struct node {
int l;
int r;
int val;
};
struct code{
int val,fl;
};
node pos[N];
int a[N],lzy2[N];
code lzy1[N];
void pushup(int u){
pos[u].val=max(pos[left(u)].val,pos[right(u)].val);
return;
}
void build(int u,int L,int R){
pos[u].l=L;pos[u].r=R;
if(L==R){
pos[u].val=a[L];
return;
}
else{
int mid=(L+R)>>1;
build(left(u),L,mid);
build(right(u),mid+1,R);
pushup(u);
}
return;
}
void maktag1(int u,int v){
lzy1[u]={v,1};
lzy2[u]=0;
pos[u].val=v;
return;
}
void maktag2(int u,int v){
lzy2[u]+=v;
pos[u].val+=v;
return;
}
void pushdown(int u){
if(lzy2[u]!=0){
maktag2(left(u),lzy2[u]);
maktag2(right(u),lzy2[u]);
lzy2[u]=0;
}
if(lzy1[u].fl)
{
maktag1(left(u),lzy1[u].val);
maktag1(right(u),lzy1[u].val);
lzy1[u].fl=0;
}
return;
}
//初始化
void update(int u,int L,int R,int add,code cg){
if(pos[u].l>=L&&pos[u].r<=R){
if(add!=0){
maktag2(u,add);
}
if(cg.fl){
maktag1(u,cg.val);
}
}
else if(!(pos[u].l>R||pos[u].r<L)){
pushdown(u);
update(left(u),L,R,add,cg);
update(right(u),L,R,add,cg);
pushup(u);
}
return;
}
int query(int u,int L,int R){
if(pos[u].l>=L&&pos[u].r<=R){
return pos[u].val;
}
else if(!(pos[u].l>R||pos[u].r<L)){
pushdown(u);
return max(query(left(u),L,R),query(right(u),L,R));
}
return -(1e9+1);
}
int n,q;
signed main(){
cin>>n>>q;
for(int i=1;i<=n;i++)cin>>a[i];
build(1,1,n);
while(q--){
int op;
cin>>op;
if(op==1){
int ll,rr,x;
cin>>ll>>rr>>x;
update(1,ll,rr,0,{x,1});
}
else if(op==2){
int ll,rr,x;
cin>>ll>>rr>>x;
update(1,ll,rr,x,{0,0});
}
else if(op==3){
int ll,rr;
cin>>ll>>rr;
cout<<query(1,ll,rr)<<"\n";
}
}
return 0;
}
by adsd45666 @ 2024-11-15 08:52:45
考虑到将其修改为0也符合规范,所以改标记修改时的条件错误,不应为 lzy2[u]!=0
而是一个改标记永远也不会达到的一个