s_mayunfeng @ 2024-11-29 10:05:34
为什么后面全WA啊
评测记录
#include<cstdio>
#define MAXN 1000005
#define inf 19198101145146666ll
#define lp p<<1
#define rp p<<1|1
#define int long long
inline int max(int a,int b){return a<b?b:a;}
int Z[MAXN],N,Q;
struct node{int lazyc,lazyf,num;}t[MAXN<<2];
inline void update(int p){t[p].num=max(t[lp].num,t[rp].num);}
inline void pushdown(int p){
if(t[p].lazyf!=inf){
t[rp].lazyf=t[lp].lazyf=t[p].lazyf;
t[rp].num=t[lp].num=t[p].lazyf;
t[lp].lazyc=t[rp].lazyc=0;
}
if(t[p].lazyc){
t[lp].lazyc+=t[p].lazyc;
t[rp].lazyc+=t[p].lazyc;
t[lp].num+=t[p].lazyc;
t[rp].num+=t[p].lazyc;
}t[p].lazyc=0;t[p].lazyf=inf;
return ;
}
void build_tree(int p,int l,int r){
int mid=(l+r)/2;
t[p].lazyf=inf;
t[p].lazyc=0;
if(l==r){
t[p].num=Z[l];
return ;
}
build_tree(lp,l,mid);
build_tree(rp,mid+1,r);
update(p);
}
void cover(int p,int l,int r,int x,int y,int val){
int mid=(l+r)/2;
if(l==x&&r==y){
t[p].num=val;
t[p].lazyf=val;
t[p].lazyc=0;
return ;
}if(l==r)return ;
pushdown(p);
if(y<=mid)cover(lp,l,mid,x,y,val);
else if(x>=mid+1)cover(rp,mid+1,r,x,y,val);
else{cover(lp,l,mid,x,mid,val);cover(rp,mid+1,r,mid+1,r,val);}
update(p);
}
void add(int p,int l,int r,int x,int y,int val){
int mid=(l+r)/2;
if(l==x&&r==y){
t[p].num+=val;
t[p].lazyc+=val;
return ;
}if(l==r)return ;
pushdown(p);
if(y<=mid)add(lp,l,mid,x,y,val);
else if(x>=mid+1)add(rp,mid+1,r,x,y,val);
else{add(lp,l,mid,x,mid,val);add(rp,mid+1,r,mid+1,y,val);}
update(p);
}
int query(int p,int l,int r,int x,int y){
int mid=(l+r)/2;
if(l==x&&r==y)return t[p].num;
if(l==r)return -inf;
pushdown(p);
if(y<=mid)return query(lp,l,mid,x,y);
else if(x>=mid+1)return query(rp,mid+1,r,x,y);
else return max(query(lp,l,mid,x,mid),query(rp,mid+1,r,mid+1,y));
}
signed main(){
scanf("%lld%lld",&N,&Q);
for(int i=1;i<=N;i++)scanf("%lld",&Z[i]);
build_tree(1,1,N);
while(Q--){
int opd,l,r,x;
scanf("%lld",&opd);
if(opd==1){
scanf("%lld%lld%lld",&l,&r,&x);
cover(1,1,N,l,r,x);
}
else if(opd==2){
scanf("%lld%lld%lld",&l,&r,&x);
add(1,1,N,l,r,x);
}
else{
scanf("%lld%lld",&l,&r);
printf("%lld\n",query(1,1,N,l,r));
}
}
return 0;
}
by aaa1145141919810 @ 2024-11-29 10:56:32
if(t[p].lazyc){
t[lp].lazyc+=t[p].lazyc;
t[rp].lazyc+=t[p].lazyc;
t[lp].num+=t[p].lazyc;
t[rp].num+=t[p].lazyc;
}t[p].lazyc=0;t[p].lazyf=inf;
这里要特判儿子有赋值标记 把值加到赋值标记上