CCF_Friend @ 2024-03-27 20:47:51
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e6+10;
int n,m,a[maxn];
struct fan
{
int l,r,sz;
long long sum,lazy,lazy1;
}t[maxn];
void pushup(int rt)
{
t[rt].sum=max(t[rt<<1].sum,t[rt<<1|1].sum);
}
void pushdown(int rt)
{
if(t[rt].lazy1!=-1000000001)
{
t[rt<<1].lazy=t[rt<<1|1].lazy=0;
t[rt<<1].sum=t[rt<<1|1].sum=t[rt].lazy1;
t[rt<<1].lazy1=t[rt<<1|1].lazy1=t[rt].lazy1;
t[rt].lazy1=-1000000001;
}
}
void pushdown1(int rt)
{
if(t[rt].lazy)
{
pushdown(rt);
t[rt<<1].sum+=t[rt].lazy;
t[rt<<1|1].sum+=t[rt].lazy;
t[rt<<1].lazy+=t[rt].lazy;
t[rt<<1|1].lazy+=t[rt].lazy;
t[rt].lazy=0;
}
}
void build(int x,int y,int rt)
{
t[rt]={x,y,y-x+1,0,0,-1000000001};
if(x==y)
{
t[rt].sum=a[x];
return;
}
int mid=(x+y)>>1;
build(x,mid,rt<<1);
build(mid+1,y,rt<<1|1);
pushup(rt);
}
void modify(int x,int y,long long k,int rt)
{
if(t[rt].l>=x&&t[rt].r<=y)
{
t[rt].sum=k;
t[rt].lazy1=k;
return;
}
pushdown(rt);
int mid=(t[rt].l+t[rt].r)>>1;
if(x<=mid) modify(x,y,k,rt<<1);
if(y>mid) modify(x,y,k,rt<<1|1);
pushup(rt);
}
void modify1(int x,int y,long long k,int rt)
{
if(t[rt].l>=x&&t[rt].r<=y)
{
t[rt].sum+=k;
t[rt].lazy+=k;
return;
}
pushdown1(rt);
int mid=(t[rt].l+t[rt].r)>>1;
if(x<=mid) modify1(x,y,k,rt<<1);
if(y>mid) modify1(x,y,k,rt<<1|1);
pushup(rt);
}
long long query(int x,int y,int rt)
{
if(t[rt].l>=x&&t[rt].r<=y) return t[rt].sum;
pushdown1(rt);
int mid=(t[rt].l+t[rt].r)>>1;
long long ans=-INT_MAX;
if(x<=mid) ans=(ans,query(x,y,rt<<1));
if(y>mid) ans=max(ans,query(x,y,rt<<1|1));
return ans;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
build(1,n,1);
for(int i=1;i<=m;i++)
{
int op,x,y,k;
cin>>op>>x>>y;
if(op==1)
{
cin>>k;
modify(x,y,k,1);
}
if(op==2)
{
cin>>k;
modify1(x,y,k,1);
}
if(op==3)
{
cout<<query(x,y,1)<<endl;
}
}
return 0;
}
by CCF_Friend @ 2024-03-27 21:20:03
此贴终,已AC,pushdown的问题