"Line segment Tree" bzoj3747 [Poi2015]kinoman

Source: Internet
Author: User

Puzzle: http://www.cnblogs.com/zyfzyf/p/4105184.html

1#include <cstdio>2#include <algorithm>3#include <cmath>4 using namespacestd;5 #defineLson rt<<1,l,m6 #defineRson Rt<<1|1,m+1,r7 intnum,ch[ A],f,c;8InlinevoidRint&x) {9C=0; f=1;Ten      for(;c<'0'|| C>'9'; C=getchar ())if(c=='-') f=-1; One      for(x=0; c>='0'&&c<='9'; C=getchar ()) (x*=Ten) + = (c'0'); Ax*=F; - } -typedefLong Longll; the intn,m,w[1000001],now[1000001],b[1000001],fa[1000001]; -ll ans,maxv[4000001],delta[4000001]; - voidPushdown (intRT) - { +     if(Delta[rt]) -       { +delta[rt<<1]+=DELTA[RT]; delta[rt<<1|1]+=Delta[rt]; Amaxv[rt<<1]+=DELTA[RT]; maxv[rt<<1|1]+=Delta[rt]; atdelta[rt]=0; -       } - } - voidUpdateintQlintQrintVintRtintLintR) - { -     if(ql<=l&&r<=qr) in       { -delta[rt]+=(ll) v; tomaxv[rt]+=(ll) v; +         return; -       } thePushdown (RT);intM=l+r>>1; *     if(ql<=m) update (Ql,qr,v,lson); $     if(m<qr) update (Ql,qr,v,rson);Panax NotoginsengMaxv[rt]=max (maxv[rt<<1],maxv[rt<<1|1]); - } thell query (intQrintRtintLintR) + { A     if(1&LT;=L&AMP;&AMP;R&LT;=QR)returnMaxv[rt]; the pushdown (RT); +     intM=l+r>>1; ll res=0; -     if(1&LT;=M) res=Max (Res,query (Qr,lson)); $     if(M&LT;QR) res=Max (Res,query (Qr,rson)); $     returnRes; - } - intMain () the { - R (n); R (m);Wuyi      for(intI=1; i<=n;++i) R (B[i]); the      for(intI=1; i<=m;++i) R (W[i]); -      for(intI=1; i<=n;++i) Wu       { -fa[i]=Now[b[i]]; Aboutnow[b[i]]=i; $       } -      for(intI=1; i<=n;++i) -       { -Update (fa[i]+1, I, (LL) W[b[i]],1,1, n); A           if(Fa[i]) update (fa[fa[i]]+1, Fa[i], (LL) (-w[b[i]),1,1, n); +Ans=max (Ans,query (i,1,1, N)); the} printf ("%lld\n", ans); -     return 0; $}

"Line segment Tree" bzoj3747 [Poi2015]kinoman

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.