#include <bits/stdc++.h>
using namespace std;
long long n,m,a[1001000];
struct node{
long long l,r,add,maxx=-1e18-1,modify=-1e18-1;
}tree[4001000];
inline long long read(){
int num=0,f=1;
char c=getchar();
while(c<48 || c>57){
if (c=='-'){
f=-1;
}
c=getchar();
}
while(c>=48 && c<=57){
num=num*10+c-48;
c=getchar();
}
return num*f;
}
inline void write(long long x){
if (x<0)putchar('-'),x=-x;
if (x>9){
write(x/10);
}
putchar(x%10+'0');
return;
}
inline void pushdown(int p){
tree[p].maxx=max(tree[p*2].maxx,tree[p*2+1].maxx);
}
inline void build(int p,int l,int r){
tree[p].l=l,tree[p].r=r;
if (l==r){
tree[p].maxx=a[l];
return;
}
long long mid=(tree[p].l+tree[p].r)/2;
build(p*2,l,mid);
build(p*2+1,mid+1,r);
pushdown(p);
}
inline void down(int p){
long long d=tree[p].add,g=tree[p].modify;
if (d>-1e18-1){
tree[p*2].add+=d;
tree[p*2+1].add+=d;
}
else{
tree[p*2].maxx=g;
tree[p*2+1].maxx=g;
tree[p*2].add=d;
tree[p*2+1].add=d;
tree[p*2].modify=g;
tree[p*2+1].modify=g;
tree[p].modify=-1e18-1;
}
tree[p*2].maxx+=d;
tree[p*2+1].maxx+=d;
tree[p].add=0;
}
inline void update(int p,int l,int r,int k){
if (tree[p].l>=l && tree[p].r<=r){
tree[p].add+=k;
tree[p].maxx+=k;
return;
}
down(p);
long long mid=(tree[p].l+tree[p].r)/2;
if (l<=mid)update(p*2,l,r,k);
if (r>mid)update(p*2+1,l,r,k);
pushdown(p);
}
inline void update1(int p,int l,int r,int k){
if (tree[p].l>=l && tree[p].r<=r){
tree[p].modify=k,tree[p].add=0,tree[p].maxx=k;
return;
}
down(p);
long long mid=(tree[p].l+tree[p].r)/2;
if (l<=mid)update1(p*2,l,r,k);
if (r>mid)update1(p*2+1,l,r,k);
pushdown(p);
}
inline long long ask(int p,int l,int r){
if (tree[p].l>=l && tree[p].r<=r){
return tree[p].maxx;
}
down(p);
long long mid=(tree[p].l+tree[p].r)/2;
long long maxxx=-1e18-1;
if (l<=mid)maxxx=max(maxxx,ask(p*2,l,r));
if (r>mid)maxxx=max(maxxx,ask(p*2+1,l,r));
return maxxx;
}
signed main(){
n=read(),m=read();
for (int i=1;i<=n;i++)cin>>a[i];
build(1,1,n);
while(m--){
int op,l,r,k;
op=read(),l=read(),r=read();
if (op==1){
k=read();
update1(1,l,r,k);
}
if (op==2){
k=read();
update(1,l,r,k);
}
if (op==3){
cout<<ask(1,l,r)<<'\n';
}
}
return 0;
}