C++#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e6 + 5;
ll tr[N * 4],tag1[N * 4],tag2[N * 4],a[N],chl[N * 4];
bool vis[N * 4];
void pshup(int o){tr[o] = max(tr[o << 1],tr[o << 1 | 1]);}
void build(int o,int l,int r){
chl[o] = 0; vis[o] = 0; tag1[o] = 0; tag2[o] = 0;
if(l == r){
tr[o] = a[l];
return;
}
int mid = (l + r) >> 1;
build(o << 1,l ,mid);
build(o << 1 | 1,mid + 1,r);
pshup(o);
}
void pshdwn(int o){
if(chl[o] == 0) return;
if(vis[o]){
tag2[o << 1] = tag2[o];
tag2[o << 1 | 1] = tag2[o];
vis[o << 1] = vis[o << 1 | 1] = 1;
tr[o << 1] = tag2[o];
tr[o << 1 | 1] = tag2[o];
tag1[o << 1] = tag1[o << 1 | 1] = 0;
chl[o << 1] = chl[o << 1 | 1] = 2;
vis[o] = 0;
tag2[o] = 0;
}
if(tag1[o]){
tr[o << 1] += tag1[o];
tr[o << 1 | 1] += tag1[o];
tag1[o << 1] += tag1[o];
tag1[o << 1 | 1] += tag1[o];
if(chl[o << 1] != 2) chl[o << 1] = 1;
if(chl[o << 1 | 1] != 2) chl[o << 1 | 1] = 1;
tag1[o] = 0;
}
chl[o] = 0;
}
void chge1(int o,int l,int r,int L,int R,int x){
if(l >= L && r <= R){
tr[o] += x;
tag1[o] += x;
if(!vis[o])chl[o] = 1;
return;
}
pshdwn(o);
int mid = (l + r) >> 1;
if(mid >= L)chge1(o << 1,l,mid,L,R,x);
if(mid < R)chge1(o << 1 | 1,mid + 1,r,L,R,x);
if(l != r)pshup(o);
}
void chge2(int o,int l,int r,int L,int R,int x){
if(l >= L && r <= R){
tr[o] = x;
tag2[o] = x;
vis[o] = 1;
chl[o] = 2;
tag1[o] = 0;
return;
}
pshdwn(o);
int mid = (l + r) >> 1;
if(mid >= L)chge2(o << 1,l,mid,L,R,x);
if(mid < R)chge2(o << 1 | 1,mid + 1,r,L,R,x);
if(l != r)pshup(o);
}
ll sch(int o,int l,int r,int L,int R){
if(l >= L && r <= R){
return tr[o];
}
pshdwn(o);
ll res = -2e18;
int mid = (l + r) >> 1;
if(mid >= L)res = max(res,sch(o << 1,l,mid,L,R));
if(mid < R)res = max(res,sch(o << 1 | 1,mid + 1,r,L,R));
return res;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,q;
cin>>n>>q;
for(int i = 1;i <= n;++i){
cin>>a[i];
}
build(1,1,n);
for(int op,x,l,r,i = 1;i <= q;++i){
cin>>op;
if(op == 1){
cin>>l>>r>>x;
chge2(1,1,n,l,r,x);
}
if(op == 2){
cin>>l>>r>>x;
chge1(1,1,n,l,r,x);
}
if(op == 3){
cin>>l>>r;
cout<<sch(1,1,n,l,r)<<"\n";
}
}
return 0;
}