RT 调对我让全机房的人都关注你
#include <bits/stdc++.h>
#define int long long
using namespace std;
const long long MAXN=10000001;
struct tree{
int l,r,max,la,lc,rev;
}t[MAXN];
int n,m,k,a[MAXN],orz,x,y;
void built(int p,int l,int r){
t[p].l=l,t[p].r=r;
t[p].max=-1e18;
if(l==r){
t[p].max=a[r];
return;
}
int mid=(l+r)/2;
built(p/2,l,mid);
built((p/2)+1,mid+1,r);
t[p].max=max(t[p/2].max,t[(p/2)+1].max);
return;
}
void pushdown(int p){
if(t[p].rev!=0){
t[p<<1].la=t[(p<<1)+1].la=t[p].la;
t[p<<1].lc=t[(p<<1)+1].lc=t[p].lc;
t[p<<1].max=t[(p<<1)+1].max=t[p].la+t[p].lc;
t[p<<1].rev=t[(p<<1)+1].rev=1;
}else{
t[p<<1].la+=t[p].la;
t[(p<<1)+1].la+=t[p].la;
t[p<<1].max+=t[p].la;
t[(p<<1)+1].max+=t[p].la;
}
t[p].la=t[p].lc=t[p].rev=0;
return ;
}
void change(int p,int l,int r,int x){
if(t[p].r<l||t[p].l>r)
return ;
if(l<=t[p].l&&t[p].r<=r){
t[p].la=0;
t[p].lc=x;
t[p].rev=1;
t[p].max=x;
return ;
}
pushdown(p);
change(p<<1,l,r,x);
change((p<<1)+1,l,r,x);
t[p].max=max(t[p<<1].max,t[(p<<1)+1].max);
return ;
}
void modify(int p,int l,int r,int x){
if(t[p].r<l||t[p].l>r)
return ;
if(l<=t[p].l&&t[p].r<=r){
t[p].la+=x;
t[p].max+=x;
return ;
}
pushdown(p);
modify(p<<1,l,r,x);
modify((p<<1)+1,l,r,x);
t[p].max=max(t[p<<1].max,t[(p<<1)+1].max);
return ;
}
int query(int p,int l,int r){
if(t[p].r<l||t[p].l>r)
return -1e18;
if(l<=t[p].l&&t[p].r<=r)
return t[p].max;
pushdown(p);
return max(query(p<<1,l,r),query((p<<1)+1,l,r));
}
signed main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
built(1,1,n);
for(int i=1;i<=m;i++){
scanf("%lld%lld%lld",&orz,&x,&y);
if(orz==1){
scanf("%lld",&k);
change(1,x,y,k);
}else if(orz==2){
scanf("%lld",&k);
modify(1,x,y,k);
}
else
printf("%lld\n",query(1,x,y));
}
return 0;
}