#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+5;
struct S {
int l,r;
long long sum,add;
}tree[MAXN*4];
int n,m,a[MAXN];
void build(int p,int l,int r){
tree[p].l=l,tree[p].r=r;
if(l==r){
tree[p].sum=a[l];
return;
}
int mid=(l+r)/2;
build(p*2,l,mid);
build(p*2+1,mid+1,r);
tree[p].sum=tree[p*2].sum+tree[p*2+1].sum;
}
void sp(int p){
if(tree[p].add){
tree[p*2].sum+=tree[p].add*(tree[p*2].r-tree[p*2].l+1);
tree[p*2+1].sum+=tree[p].add*(tree[p*2+1].r-tree[p*2+1].l+1);
tree[p*2].add+=tree[p].add;
tree[p*2+1].add+=tree[p].add;
tree[p].add=0;
}
}
void ch(int p,int l,int r,int d){
if(l<=tree[p].l&&r>=tree[p].r){
tree[p].sum+=(long long)d*(tree[p].r-tree[p].l+1);
tree[p].add+=d;
return;
}
sp(p);
int mid=(tree[p].l+tree[p].r)/2;
if(l<=mid){ch(p*2,l,r,d);}
if(r>mid){ch(p*2+1,l,r,d);}
tree[p].sum=tree[p*2].sum+tree[p*2+1].sum;
}
void df(int p,int l,int r,int d){
if(l<=tree[p].l&&r>=tree[p].r){
tree[p].sum=d;;
tree[p].add=0;
return;
}
sp(p);
int mid=(tree[p].l+tree[p].r)/2;
if(l<=mid){ch(p*2,l,r,d);}
if(r>mid){ch(p*2+1,l,r,d);}
tree[p].sum=tree[p*2].sum+tree[p*2+1].sum;
}
long long ask(int p,int l,int r){
if(l<=tree[p].l&&r>=tree[p].r){
return tree[p].sum;
}
sp(p);
int mid=(tree[p].l+tree[p].r)/2;
long long val=-INT_MAX;
if(l<=mid){val=max(val,ask(p*2,l,r));}
if(r>mid){val=max(val,ask(p*2+1,l,r));}
return val;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
build(1,1,n);
while(m--){
int op,l,r,d;
cin>>op>>l>>r;
if(op==1){
cin>>d;
ch(1,l,r,d);
} else if(op==2){
cin>>d;
df(1,l,r,d);
} else {
cout<<ask(1,l,r)<<"\n";
}
}
return 0;
}