lian13817981484 @ 2023-02-11 12:38:00
#include<cstdio>
using namespace std;
int max(int a,int b){
return a < b ? b : a;
}
int n,m,a,b,c,d,tree[400005],tag[400005],tag2[400005],arr[100005];
void asdf(int z){
tree[z] = max(tree[z<<1],tree[z<<1|1]);
}
void fdsa2(int x,int y,int z){
if(tag2[z] != -12345678901234){
int mid = x+y>>1;
tag2[z<<1] = 0;
tag2[z<<1|1] = 0;
tree[z<<1] = tag2[z]*(mid-x+1);
tree[z<<1|1] = tag2[z]*(y-mid);
tag2[z] = -12345678901234;
}
}
void fdsa(int x,int y,int z){
if(tag[z]){
fdsa2(x);
int mid = x+y>>1;
tag[z<<1] += tag[z];
tag[z<<1|1] += tag[z];
tree[z<<1] += tag[z]*(mid-x+1);
tree[z<<1|1] += tag[z]*(y-mid);
tag[z] = 0;
}
}
void change(int x,int y,int z){
tree[z] = arr[x];
if(x == y){
return;
}
int mid = x+y>>1;
change(x,mid,z<<1);
change(mid+1,y,z<<1|1);
asdf(z);
}
void update(int l,int r,int z,int x,int y,int k){
if(x <= l && r <= y && l <= r){
tree[z] += k * (r-l+1);
tag[z] += k;
return;
}
fdsa(l,r,z);
fdsa2(l,r,z);
int mid = l+r>>1;
if(x <= mid)update(l,mid,z<<1,x,y,k);
if(y > mid)update(mid+1,r,z<<1|1,x,y,k);
asdf(z);
}
void update2(int l,int r,int z,int x,int y,int k){
if(x <= l && r <= y && l <= r){
tree[z] = k * (r-l+1);
tag2[z] = k;
return;
}
fdsa(l,r,z);
fdsa2(l,r,z);
int mid = l+r>>1;
if(x <= mid)update2(l,mid,z<<1,x,y,k);
if(y > mid)update2(mid+1,r,z<<1|1,x,y,k);
asdf(z);
}
int fmax(int x,int y,int z,int l,int r){
if(x <= l/*1*/ && r/*n*/ <= y)return tree[z];
int mid = l+r>>1,ans = 0;
if(x <= mid)ans = max(ans,fmax(x,y,z<<1,l,mid));
if(y > mid)ans = max(ans,fmax(x,y,z<<1|1,mid+1,r));
return ans;
}
int main(){
scanf("%d %d",&n,&m);
for(int i = 1;i <= n;i++){
scanf("%d",&arr[i]);
}
change(1,n,1);
for(int i = 1;i <= m;i++){
scanf("%d %d %d",&a,&b,&c);
if(a == 1){
scanf("%d",&d);
update2(1,n,1,b,c,d);
}
else if(a == 2){
scanf("%d",&d);
update(1,n,1,b,c,d);
}
else printf("%d\n",fmax(b,c,1,1,n));
/*printf("{");
for(int i = 1;i <= 4*n;i++){
printf("%d ",tree[i]);
}
printf("}\n");*/
}
return 0;
}