求调,或给个hack(玄关)

P1253 扶苏的问题

**hack** ``` 3 4 1 2 3 2 1 2 3 1 1 3 2 2 3 3 1 3 1 1 ``` 正确答案是2,程序输出为5 原因:pushdownx的时候,不仅要修改儿子的lazyx,还需要清空儿子的lazy,对,清零。 亲测可以通过hack
by IamZZ @ 2023-10-09 14:46:57


谢谢
by kk_is_ethereal @ 2023-10-09 14:53:32


可是还是WA50pts诶 @[IamZZ](/user/552509)
by kk_is_ethereal @ 2023-10-09 14:56:35


```cpp #include<bits/stdc++.h> using namespace std; #define int long long inline void read(int &x) { x=0; short flag=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')flag = -1; c=getchar(); } while(c >= '0' && c <= '9'){ x=(x<<3)+(x<<1)+(c^48); c=getchar(); } x*=flag; } const int nul=1e18; int n,a[200010],m; struct tree{ int v,l,r,lazy,lazyx; }t[10000000]; void build(int x,int l,int r){ t[x].l=l,t[x].r=r; t[x].lazy=t[x].lazyx=nul; if(l==r){ t[x].v=a[l]; return; } build(x<<1,l,(l+r)>>1); build(x<<1|1,((l+r)>>1)+1,r); t[x].v=max(t[x<<1].v,t[x<<1|1].v); } void push_down(int x){ t[x<<1].lazy+=t[x].lazy; t[x<<1].lazy%=nul; t[x<<1|1].lazy+=t[x].lazy; t[x<<1|1].lazy%=nul; t[x<<1].v+=t[x].lazy; t[x<<1|1].v+=t[x].lazy; t[x].lazy=nul; } void push_downx(int x){ t[x<<1].lazyx=t[x].lazyx; t[x<<1].lazy=nul; t[x<<1|1].lazyx=t[x].lazyx; t[x<<1|1].lazy=nul; t[x<<1].v=t[x].lazyx; t[x<<1|1].v=t[x].lazyx; t[x].lazyx=nul; } void update(int x){ if(t[x].lazyx!=nul)push_downx(x); if(t[x].lazy!=nul)push_down(x); } void xiu(int x,int l,int r,int v){ if(l<=t[x].l&&t[x].r<=r){ t[x].v=v; t[x].lazy=nul; t[x].lazyx=v; return; } update(x); if(l<=t[x<<1].r)xiu(x<<1,l,r,v); if(r>=t[x<<1|1].l)xiu(x<<1|1,l,r,v); t[x].v=max(t[x<<1].v,t[x<<1|1].v); } void add(int x,int l,int r,int v){ if(l<=t[x].l&&t[x].r<=r){ t[x].v+=v; if(t[x].lazyx!=nul)t[x].lazyx+=v; else t[x].lazy=(t[x].lazy+v)%nul; return; } update(x); if(l<=t[x<<1].r)add(x<<1,l,r,v); if(r>=t[x<<1|1].l)add(x<<1|1,l,r,v); t[x].v=max(t[x<<1].v,t[x<<1|1].v); } int search(int x,int l,int r){ if(l<=t[x].l&&t[x].r<=r)return t[x].v; update(x); int s=-nul; if(l<=t[x<<1].r)s=max(s,search(x<<1,l,r)); if(r>=t[x<<1|1].l)s=max(s,search(x<<1|1,l,r)); return s; } signed main(){ read(n),read(m); for(int i=1;i<=n;i++)read(a[i]); build(1,1,n); for(int i=1;i<=m;i++){ int opt,l,r; read(opt),read(l),read(r); if(opt==1){ int x; read(x); xiu(1,l,r,x); } if(opt==2){ int x; read(x); add(1,l,r,x); } if(opt==3){ printf("%lld\n",search(1,l,r)); } } return 0; } ```
by kk_is_ethereal @ 2023-10-09 14:57:26


过了
by kk_is_ethereal @ 2023-10-09 16:10:31


@[kk_is_ethereal](/user/726368) add的时候不要修改lazyx(乐
by IamZZ @ 2023-10-09 16:16:32


@[IamZZ](/user/552509) 已经过了谢谢
by kk_is_ethereal @ 2023-10-09 16:26:02


@[kk_is_ethereal](/user/726368) OK
by IamZZ @ 2023-10-09 16:28:30


|