50分求助!

P1253 扶苏的问题

@[galiyuebing](/user/251775) 大佬救救我
by tang_mx @ 2023-08-22 21:41:26


@[tang_mx](/user/515833) ``` #include<iostream> #include<cstdio> using namespace std; const int N=1e6+10; const long long inf=-1e15; typedef long long ll; struct Segment{ ll l,r,add1,add2,sum,dat; #define l(x) tree[x].l #define r(x) tree[x].r #define add1(x) tree[x].add1 #define add2(x) tree[x].add2 #define dat(x) tree[x].dat }tree[N*4]; ll n,m,a[N]; #define lc p<<1 #define rc p<<1|1 void build(ll p,ll l,ll r){ l(p)=l,r(p)=r;add1(p)=inf; if(l==r){ dat(p)=a[l]; return ; } ll mid=(l+r)>>1; build(p<<1,l,mid); build(p<<1|1,mid+1,r); dat(p)=max(dat(p<<1),dat(p<<1|1)); } void spread(ll p){ if(add1(p)!=inf){ dat(p<<1)=add1(p); dat(p<<1|1)=add1(p); add1(p<<1)=add1(p); add1(p<<1|1)=add1(p); add2(p<<1)=add2(p<<1|1)=0;// add1(p)=inf; } if(add2(p)){// dat(p<<1)+=add2(p); dat(p<<1|1)+=add2(p); add2(p<<1)+=add2(p); add2(p<<1|1)+=add2(p); add2(p)=0; } } void change(ll p,ll l,ll r,ll k){ if(l<=l(p)&&r>=r(p)){ dat(p)=k; add1(p)=k; add2(p)=0; return ; } ll mid=(l(p)+r(p))>>1; spread(p); if(l<=mid)change(p<<1,l,r,k); if(r>mid)change(p<<1|1,l,r,k); dat(p)=max(dat(p<<1),dat(p<<1|1)); } void addd(ll p,ll l,ll r,ll k) { if(l<=l(p)&&r>=r(p)) { dat(p)+=k;// add2(p)+=k; return ; } ll mid=(l(p)+r(p))>>1; spread(p); if(l<=mid)addd(lc,l,r,k); if(r>mid)addd(rc,l,r,k); dat(p)=max(dat(lc),dat(rc)); } ll ask(ll p,ll l,ll r){ if(l<=l(p)&&r>=r(p))return dat(p); spread(p); ll mid=(l(p)+r(p))>>1; ll ans=inf;// if(l<=mid)ans=max(ans,ask(lc,l,r)); if(r>mid)ans=max(ans,ask(rc,l,r)); return ans; } int main(){ // freopen("P1253_7.in","r",stdin); // freopen("1.out","w",stdout); scanf("%lld%lld",&n,&m); for(int i=1;i<=n;i++)scanf("%lld",&a[i]); build(1,1,n); ll opt,x,y,k; for(int i=1;i<=m;i++){ scanf("%lld%lld%ld",&opt,&x,&y); if(opt==1){ scanf("%lld",&k); change(1,x,y,k); } else if(opt==2){ scanf("%lld",&k); addd(1,x,y,k); } else printf("%lld\n",ask(1,x,y)); } return 0; } ```
by bzzltl @ 2023-08-23 08:39:35


@[tang_mx](/user/515833) 马蜂改改吧,改不动直接
by bzzltl @ 2023-08-23 08:40:41


强烈建议改马蜂,还有宏定义,调代码调得心态都要崩了
by bzzltl @ 2023-08-23 08:44:36


@[bzzltl](/user/699852) 马蜂跟李煜东学的QAQ
by tang_mx @ 2023-08-23 12:31:45


@[bzzltl](/user/699852) 非常感谢!
by tang_mx @ 2023-08-23 12:45:28


|