BalanceSegment @ 2023-01-18 11:10:51
#include<bits/stdc++.h>
#define int long long
using namespace std;
namespace Tree{
const int maxn=1000005;
int n,q;
int val[maxn];
struct tree{
int l,r;
int lson,rson;
int maxx;
int cov,add;
}a[maxn*4];
void pushup(int x){
a[x].maxx=max(a[a[x].lson].maxx,a[a[x].rson].maxx);
}
int cnt=0;
int Root;
void Build(int &x,int l,int r){
if(x==0){
x=++cnt;
a[x].l=l;
a[x].r=r;
a[x].add=0;
a[x].cov=-1;
}
if(l==r){
a[x].maxx=val[l];
return ;
}
int mid=(l+r)/2;
Build(a[x].lson,l,mid);
Build(a[x].rson,mid+1,r);
pushup(x);
}
void coverdown(int x){
if(a[x].cov!=-1){
a[a[x].lson].maxx=a[x].cov;
a[a[x].rson].maxx=a[x].cov;
a[a[x].lson].cov=a[x].cov;
a[a[x].rson].cov=a[x].cov;
a[x].cov=-1;
}
}
void plusdown(int x){
if(a[x].add!=0){
a[a[x].lson].maxx+=a[x].add;
a[a[x].rson].maxx+=a[x].add;
a[a[x].lson].add+=a[x].add;
a[a[x].rson].add+=a[x].add;
a[x].add=0;
}
}
void cover(int x,int l,int r,int y){
if(a[x].r<l||a[x].l>r)
return ;
if(l<=a[x].l&&a[x].r<=r){
a[x].maxx=y;
a[x].cov=y;
a[x].add=0;
return ;
}
coverdown(x);
int mid=(a[x].l+a[x].r)/2;
if(l<=mid) cover(a[x].lson,l,r,y);
if(mid<r) cover(a[x].rson,l,r,y);
pushup(x);
}
void plus(int x,int l,int r,int y){
if(a[x].r<l||a[x].l>r)
return ;
if(l<=a[x].l&&a[x].r<=r){
a[x].maxx+=y;
a[x].add+=y;
return ;
}
plusdown(x);
int mid=(a[x].l+a[x].r)/2;
if(l<=mid) plus(a[x].lson,l,r,y);
if(mid<r) plus(a[x].rson,l,r,y);
pushup(x);
}
long long ans=-9223372036854775808;
void Ask(int x,int l,int r){
if(a[x].r<l||a[x].l>r)
return ;
if(l<=a[x].l&&a[x].r<=r){
ans=a[x].maxx>ans?a[x].maxx:ans;
return ;
}
coverdown(x);
plusdown(x);
int mid=(a[x].l+a[x].r)/2;
if(l<=mid) Ask(a[x].lson,l,r);
if(mid<r) Ask(a[x].rson,l,r);
pushup(x);
}
int main(){
cin>>n>>q;
for(int i=1;i<=n;i++)
cin>>val[i];
Build(Root,1,n);
while(q--){
int op;
cin>>op;
if(op==1){
int l,r,x;
cin>>l>>r>>x;
cover(Root,l,r,x);
}
else if(op==2){
int l,r,x;
cin>>l>>r>>x;
plus(Root,l,r,x);
}
else{
int l,r;
cin>>l>>r;
ans=-9223372036854775808;
Ask(Root,l,r);
cout<<ans<<"\n";
}
}
return 0;
}
}
signed main(){
//freopen("P1253_7.in","r",stdin);
//freopen("new.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
Tree::main();
return 0;
}