_youdu666_ @ 2022-07-07 12:49:45
#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;
inline int max(int a,int b)
{
return a>b?a:b;
}
inline int read()
{
int x=0,y=1;
char c=getchar();
while(c>'9'||c<'0')
{
if(c=='-')
y=-1;
c=getchar();
}
while(c<='9'&&c>='0')
x=x*10+c-48,c=getchar();
return x*y;
}
const int N=1000001,INF=9223372036854775807;
struct kof{
int sum,tag,tagb;
bool used;
}tree[N<<2];
int a[N],n,m;
void build(int k,int l,int r)
{
if(l==r)
{
tree[k].sum=a[l];
return;
}
int mid=l+r>>1;
build(k<<1,l,mid);
build(k<<1|1,mid+1,r);
tree[k].sum=max(tree[k<<1].sum,tree[k<<1|1].sum);
return;
}
inline void adda(int k,int v)
{
tree[k].tag+=v;
tree[k].sum+=v;
return;
}
inline void addb(int k,int v)
{
tree[k].tagb+=v;
tree[k].sum=tree[k].tagb;
tree[k].used=true;
return;
}
inline void pushdown(int k)
{
if(tree[k].used)
{
tree[k<<1].tag=tree[k].tag;
tree[k<<1].tagb=tree[k].tagb;
tree[k<<1].sum=tree[k].tag+tree[k].tagb;
tree[k<<1].used=true;
tree[k<<1|1].tag=tree[k].tag;
tree[k<<1|1].tagb=tree[k].tagb;
tree[k<<1|1].sum=tree[k].tag+tree[k].tagb;
tree[k<<1|1].used=true;
}
else
{
tree[k<<1].tag+=tree[k].tag;
tree[k<<1].sum+=tree[k].tag;
tree[k<<1|1].tag+=tree[k].tag;
tree[k<<1|1].sum+=tree[k].tag;
}
tree[k].tag=0;
tree[k].tagb=0;
tree[k].used=false;
return;
}
void update(int k,int l,int r,int x,int y,int v)
{
if(x<=l&&r<=y)
{
adda(k,v);
return;
}
pushdown(k);
int mid=l+r>>1;
if(x<=mid)
update(k<<1,l,mid,x,y,v);
if(y>mid)
update(k<<1|1,mid+1,r,x,y,v);
tree[k].sum=max(tree[k<<1].sum,tree[k<<1|1].sum);
return;
}
void updateb(int k,int l,int r,int x,int y,int v)
{
if(x<=l&&r<=y)
{
addb(k,v);
return;
}
pushdown(k);
int mid=l+r>>1;
if(x<=mid)
updateb(k<<1,l,mid,x,y,v);
if(y>mid)
updateb(k<<1|1,mid+1,r,x,y,v);
tree[k].sum=max(tree[k<<1].sum,tree[k<<1|1].sum);
return;
}
int query(int k,int l,int r,int x,int y)
{
if(l>y||r<x) return -INF;
if(l>=x&&r<=y)
return tree[k].sum;
int mid=l+r>>1;
pushdown(k);
return max(query(k<<1,l,mid,x,y),query(k<<1|1,mid+1,r,x,y));
}
signed main()
{
int x,y,v;
n=read(),m=read();
for(int i=1;i<=n;i++)
a[i]=read();
build(1,1,n);
for(int i=1;i<=m;i++)
{
int q=read();
if(q==1)
{
x=read(),y=read(),v=read();
updateb(1,1,n,x,y,v);
}
if(q==2)
{
x=read(),y=read(),v=read();
update(1,1,n,x,y,v);
}
if(q==3)
{
x=read(),y=read();
printf("%lld\n",query(1,1,n,x,y));
}
}
}