qz

P1253 扶苏的问题

a?
by Elysian_Realme @ 2024-04-06 18:30:17


@[Elysian_Realme](/user/1034667) 没过样例
by Coder2021 @ 2024-04-06 18:36:45


``` #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1000005; struct node{ ll max,add=0,cover=0x7f7f7f7f; int l,r,len; }tree[N<<2]; int a[N],q,n,op,x,y; ll k; void push_up(int p){ tree[p].max=max(tree[p<<1].max,tree[p<<1|1].max); } void build(int p,int l,int r){ tree[p].l=l; tree[p].r=r; tree[p].add=0; tree[p].len=r-l+1; if(l==r){ tree[p].max=a[l]; return; } int mid=l+(r-l>>1); build(p<<1,l,mid); build(p<<1|1,mid+1,r); push_up(p); } void push_down(int p){ if(tree[p].cover!=0x7f7f7f7f){ tree[p<<1].add=tree[p<<1|1].add=0; tree[p<<1].cover=tree[p<<1|1].cover=tree[p].cover; tree[p<<1].max=tree[p<<1|1].max=tree[p].cover; tree[p].cover=0x7f7f7f7f; } if(tree[p].add){ tree[p<<1].add+=tree[p].add; tree[p<<1|1].add+=tree[p].add; tree[p<<1].max+=tree[p].add; tree[p<<1|1].max+=tree[p].add; tree[p].add=0; } } void update_add(int p,ll v,int l,int r){ if(tree[p].l>r||tree[p].r<l)return; if(tree[p].l>=l&&tree[p].r<=r){ tree[p].max+=v; if(tree[p].l<tree[p].r){ if(tree[p].cover==0x7f7f7f7f)tree[p].add+=v; else tree[p].cover+=v; } return; } push_down(p); update_add(p<<1,v,l,r); update_add(p<<1|1,v,l,r); push_up(p); } void update_cover(int p,ll v,int l,int r){ if(tree[p].l>r||tree[p].r<l)return; if(tree[p].l>=l&&tree[p].r<=r){ tree[p].max=v; if(tree[p].l<tree[p].r){ tree[p].add=0; tree[p].cover=v; } return; } push_down(p); update_cover(p<<1,v,l,r); update_cover(p<<1|1,v,l,r); push_up(p); } ll query(int p,int l,int r){ if(tree[p].l>r||tree[p].r<l)return -1e18; if(tree[p].l>=l&&tree[p].r<=r)return tree[p].max; push_down(p); return max(query(p<<1,l,r),query(p<<1|1,l,r)); } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n>>q; for(int i=1;i<=n;++i)cin>>a[i]; build(1,1,n); for(int i=1;i<=q;++i){ cin>>op>>x>>y; if(op==1){ cin>>k; update_cover(1,k,x,y); } else if(op==2){ cin>>k; update_add(1,k,x,y); } else{ cout<<query(1,x,y)<<"\n"; } } return 0; }``` @[Coder2021](/user/577241)
by 123456jiangyuxuan @ 2024-04-06 19:01:56


@[Coder2021](/user/577241)
by 123456jiangyuxuan @ 2024-04-06 19:05:14


谢谢
by Coder2021 @ 2024-04-09 16:48:34


|