rt,调疯了
#include <iostream>
#include <cstdio>
using namespace std;
const int N=1e6+10;
long long xxx=-1e18-1;
typedef long long ll;
struct node{
ll p,lef,righ,sum,tag1,tag2;
}a[N*4];
ll num[N],n,q,op,le,ri,x;
void update(ll p){
a[p].sum=max(a[2*p].sum,a[2*p+1].sum);
return;
}
void push_down(ll p,ll ls,ll rs){
if(a[p].tag1!=xxx){
a[ls].sum=a[p].tag1,a[ls].tag1=a[p].tag1,a[ls].tag2=0;
a[rs].sum=a[p].tag1,a[rs].tag1=a[p].tag1,a[rs].tag2=0;
a[p].tag1=xxx;return;
}else{
if(a[ls].tag1!=xxx)a[ls].tag1+=a[p].tag2,a[ls].sum=a[ls].tag2;
else a[ls].tag2+=a[p].tag2,a[ls].sum+=a[p].tag2;
if(a[rs].tag1!=xxx)a[rs].tag1+=a[p].tag2,a[rs].sum=a[rs].tag2;
else a[rs].tag2+=a[p].tag2,a[rs].sum+=a[p].tag2;
a[p].tag2=0;return;
}
}
void build(ll p,ll l,ll r){
if(l==r){
a[p]=node{p,l,r,num[l],xxx,0};
return;
}else{
ll mid=(l+r)/2;
build(2*p,l,mid);
build(2*p+1,mid+1,r);
a[p]=node{p,l,r,0,xxx,0};
update(p);
return;
}
}
void add1(ll p,ll l,ll r,ll x){
if(a[p].lef>=l&&a[p].righ<=r){
if(a[p].tag1!=xxx)a[p].tag1+=x,a[p].sum+=x;
else a[p].tag2+=x,a[p].sum+=x;
return;
}else{
ll mid=(a[p].lef+a[p].righ)/2;
push_down(p,2*p,2*p+1);
if(mid>=l)add1(2*p,l,r,x);
if(mid<r)add1(2*p+1,l,r,x);
update(p);
return;
}
}
void add2(ll p,ll l,ll r,ll x){
if(a[p].lef>=l&&a[p].righ<=r){
a[p].tag1=a[p].tag2=0;
a[p].tag1=x,a[p].sum=x;
return;
}else{
ll mid=(a[p].lef+a[p].righ)/2;
push_down(p,2*p,2*p+1);
if(mid>=l)add2(2*p,l,r,x);
if(mid<r)add2(2*p+1,l,r,x);
update(p);
return;
}
}
ll sum(ll p,ll l,ll r){
if(a[p].lef>=l&&a[p].righ<=r)return a[p].sum;
else{
ll mid=(a[p].lef+a[p].righ)/2,cnt=-1145141919810;
push_down(p,2*p,2*p+1);
if(mid>=l)cnt=max(cnt,sum(2*p,l,r));
if(mid<r)cnt=max(cnt,sum(2*p+1,l,r));
return cnt;
}
}
int main(){
scanf("%lld %lld",&n,&q);
for(int i=1;i<=n;i++)scanf("%lld",num+i);
build(1,1,n);
while(q--){
scanf("%lld",&op);
if(op==1)scanf("%lld %lld %lld",&le,&ri,&x),add2(1,le,ri,x);
if(op==2)scanf("%lld %lld %lld",&le,&ri,&x),add1(1,le,ri,x);
if(op==3)scanf("%lld %lld",&le,&ri),printf("%lld\n",sum(1,le,ri));
}
return 0;
}