gaomingyang101011 @ 2024-09-26 18:31:01
#include<iostream>
using namespace std;
const int minn=-1e9-1;
const int N=1e6+6;
int n,q;
int a[N];
int op,l,r,x;
int f[N<<2];
int xg[N<<2],jia[N<<2];
bool visxg[N<<2];
int ans;
void build(int l,int r,int i){
if(l==r){
f[i]=a[l];
return ;
}
int mid=(l+r)/2;
build(l,mid,i*2);
build(mid+1,r,i*2+1);
f[i]=max(f[i*2],f[i*2+1]);
}
void tree1(int l,int r,int sl,int sr,int s,int i){
if(l==r||(l==sl&&r==sr)){
visxg[i]=1,xg[i]=s;
jia[i]=0;
f[i]=s;
return ;
}
int mid=(l+r)/2;
if(visxg[i]!=0) f[i*2]=xg[i],f[i*2+1]=xg[i],visxg[i]=0;
f[i*2]+=jia[i],f[i*2+1]+=jia[i],jia[i]=0;
if(sl<=mid) tree1(l,mid,sl,min(sr,mid),s,i*2);
if(sr>mid) tree1(mid+1,r,max(sl,mid+1),sr,s,i*2+1);
f[i]=max(f[i*2],f[i*2+1]);
}
void tree2(int l,int r,int sl,int sr,int s,int i){
if(l==r||(l==sl&&r==sr)){
jia[i]+=s;
f[i]+=s;
return ;
}
int mid=(l+r)/2;
if(visxg[i]!=0) f[i*2]=xg[i],f[i*2+1]=xg[i],visxg[i]=0;
f[i*2]+=jia[i],f[i*2+1]+=jia[i],jia[i]=0;
if(sl<=mid) tree2(l,mid,sl,min(sr,mid),s,i*2);
if(sr>mid) tree2(mid+1,r,max(sl,mid+1),sr,s,i*2+1);
f[i]=max(f[i*2],f[i*2+1]);
}
void tree3(int l,int r,int sl,int sr,int i){
if(l==r||(l==sl&&r==sr)){
ans=max(ans,f[i]);
return ;
}
int mid=(l+r)/2;
if(visxg[i]!=0) f[i*2]=xg[i],f[i*2+1]=xg[i],visxg[i]=0;
f[i*2]+=jia[i],f[i*2+1]+=jia[i],jia[i]=0;
if(sl<=mid) tree3(l,mid,sl,min(sr,mid),i*2);
if(sr>mid) tree3(mid+1,r,max(sl,mid+1),sr,i*2+1);
}
int main(){
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
build(1,n,1);
while(q--){
scanf("%d%d%d",&op,&l,&r);
if(op==1){
scanf("%d",&x);
tree1(1,n,l,r,x,1);
}
else if(op==2){
scanf("%d",&x);
tree2(1,n,l,r,x,1);
}
else{
ans=minn;
tree3(1,n,l,r,1);
printf("%d\n",ans);
}
}
return 0;
}