Wa #6 #7 #8 #9 #10
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 10;
int mx[4*N],val[4*N],mp[4*N],add[4*N],n,q,opt,l,r,ans;
void build(int s,int t,int p){
if(s==t){
mx[p]=val[s]; //最大值
mp[p]=LLONG_MAX; //改变
add[p]=0; //加法
return ;
}
int m=s+t>>1;
build(s,m,p*2); build(m+1,t,p*2+1);
mx[p]=max(mx[p*2],mx[p*2+1]);
mp[p]=LLONG_MAX;
}
void push_down(int p){
if(mp[p]!=LLONG_MAX){
mp[p*2]=mp[p]; mp[p*2+1]=mp[p];
mx[p*2]=mp[p]; mx[p*2+1]=mp[p];
}
else if(add[p]!=0){
add[p*2]+=add[p]; add[p*2+1]+=add[p];
mx[p*2]+=add[p]; mx[p*2+1]+=add[p];
}
mp[p]=LLONG_MAX; add[p]=0;
return ;
}
void updata_add(int l,int r,int s,int t,int p,int x){
if(s>r||t<l)return ;
if(l<=s&&t<=r){
mx[p]+=x;
add[p]+=x;
return ;
}
push_down(p);
int m=s+t>>1;
updata_add(l,r,s,m,p*2,x);
updata_add(l,r,m+1,t,p*2+1,x);
mx[p]=max(mx[p*2],mx[p*2+1]);
return ;
}
void updata_mp(int l,int r,int s,int t,int p,int x){
if(s>r||t<l)return ;
if(l<=s&&t<=r){
mx[p]=x;
add[p]=0;
mp[p]=x;
return ;
}
push_down(p);
int m=s+t>>1;
updata_mp(l,r,s,m,p*2,x);
updata_mp(l,r,m+1,t,p*2+1,x);
mx[p]=max(mx[p*2],mx[p*2+1]);
return ;
}
void query(int l,int r,int s,int t,int p){
if(s>r||t<l)return ;
if(l<=s&&t<=r){
ans=max(ans,mx[p]);
return ;
}
push_down(p);
int m=s+t>>1;
query(l,r,s,m,p*2);
query(l,r,m+1,t,p*2+1);
mx[p]=max(mx[p*2],mx[p*2+1]);
return ;
}
int read(){
int x=0,f=1;
char ch=getchar();
while(ch>'9'||ch<'0'){
if(ch=='-')f=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
x=(x<<3)+(x<<1)+(ch^48);
ch=getchar();
}
return x*f;
}
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
n=read(); q=read();
for(int i=1;i<=n;++i) val[i]=read();
build(1,n,1);
while(q--){
opt=read(); l=read(); r=read();
if(opt==1) {
updata_mp(l,r,1,n,1,read());
}
else if(opt==2) {
updata_add(l,r,1,n,1,read());
}
else {
ans=INT_MIN;
query(l,r,1,n,1);
cout<<ans<<'\n';
}
}
return 0;
}
/*
6 6
1 1 4 5 1 4
2 1 2 4
2 3 3 1
2 5 6 1
2 5 5 3
1 1 6 3
3 1 6
*/