可爱的小棉羊 @ 2023-08-30 11:55:46
#include<bits/stdc++.h>
using namespace std;
struct node{
int l,r;
long long maxx,tag,tag2;
}v[4000006];
int n,a[1000006],q;
void push_up(int rt){
v[rt].maxx=max(v[rt<<1].maxx,v[rt<<1|1].maxx);
}
void push_tag(int rt,int val){
v[rt].maxx+=val;
v[rt].tag+=val;
}
void push_tag2(int rt,int val){
if(val==1e9+1)return;
v[rt].maxx=val;
v[rt].tag2=val;
v[rt].tag=0;
}
void push_down(int rt){
push_tag2(rt<<1,v[rt].tag2);
push_tag2(rt<<1|1,v[rt].tag2);
push_tag(rt<<1,v[rt].tag);
push_tag(rt<<1|1,v[rt].tag);
v[rt].tag=0;
v[rt].tag2=1e9+1;
}
void build(int rt,int l,int r){
v[rt].l=l;
v[rt].r=r;
v[rt].tag=0;
v[rt].tag2=1e9+1;
if(l==r){
v[rt].maxx=a[l];
return;
}
int mid=(l+r)>>1;
build(rt<<1,l,mid);
build(rt<<1|1,mid+1,r);
push_up(rt);
return;
}
void add(int rt,int l,int r,int val){
if(l<=v[rt].l&&v[rt].r<=r){
push_tag(rt,val);
return;
}
push_down(rt);
int mid=(v[rt].l+v[rt].r)>>1;
if(l<=mid)add(rt<<1,l,r,val);
if(r>=mid+1)add(rt<<1|1,l,r,val);
push_up(rt);
}
void seti(int rt,int l,int r,int val){
if(l<=v[rt].l&&v[rt].r<=r){
push_tag2(rt,val);
return;
}
push_down(rt);
int mid=(v[rt].l+v[rt].r)>>1;
if(l<=mid)seti(rt<<1,l,r,val);
if(r>=mid+1)seti(rt<<1|1,l,r,val);
push_up(rt);
return;
}
int ask(int rt,int l,int r){
if(l<=v[rt].l&&v[rt].r<=r){
return v[rt].maxx;
}
push_down(rt);
int mid=(v[rt].l+v[rt].r)>>1,maxx=-1e9-1;
if(l<=mid)maxx=max(ask(rt<<1,l,r),maxx);
if(r>=mid+1)maxx=max(ask(rt<<1|1,l,r),maxx);
return maxx;
}
int main(){
cin>>n>>q;
for(int i=1;i<=n;i++)cin>>a[i];
build(1,1,n);
while(q--){
int op;
cin>>op;
if(op==2){
int l,r,x;
cin>>l>>r>>x;
add(1,l,r,x);
}else if(op==1){
int l,r,x;
cin>>l>>r>>x;
seti(1,l,r,x);
}else{
int l,r;
cin>>l>>r;
cout<<ask(1,l,r)<<endl;
}
}
}
by _Fancy_ @ 2023-09-01 19:47:33
@可爱的小棉羊 1e9+1太小了,全改成1e15就行了
by 可爱的小棉羊 @ 2023-09-02 09:07:11
@sxy2012yutiti 感谢调分
我AC了