Luogu P1607 Temple Fair Shuttle "line Tree" by cellur925

Source: Internet
Author: User

Topic Portal

Is it said that you can do it with greed? Forget it... I will not be greedy ....

Start thinking is to use a line tree, first built an empty tree, and then into the interval operation to maintain the maximum value, obviously started I overlooked the capacity of the bus and can have more than one group of cows sitting together information.

We certainly want to have more of the interval is selected, according to the pattern of the line coverage problem, we have to choose the end position of the smallest, can choose to choose, but need to judge whether can choose, is to compare the current interval maximum and capacity of the relationship, as far as possible, to modify. To be blunt is to maintain the maximum interval of the band modification.

Code

1#include <cstdio>2#include <algorithm>3 4 using namespacestd;5 6 intK,n,c,ans;7 structmoo{8     intf,t,sum;9}cow[50090];Ten structsegmenttree{ One     intL,r,val,lazy; A}t[20090*4]; -  - BOOLCMP (Moo A,moo B) the { -     returna.t<b.t; - } -  + voidBuildintPintLintR) - { +T[p].l=l,t[p].r=R; A     if(L==R)return ; at     intMid= (l+r) >>1; -Build (p*2, l,mid); -Build (p*2+1, mid+1, R); - } -  - voidUpdateintp) in { -     if(!t[p].lazy)return ; to     if(T[P].L==T[P].R)return ; +t[p*2].val+=T[p].lazy; -t[p*2+1].val+=T[p].lazy; thet[p*2].lazy+=T[p].lazy; *t[p*2+1].lazy+=T[p].lazy; $t[p].lazy=0;Panax Notoginseng } -  the voidChangeintPintLintRintx) + { A Update (p); the     if(t[p].l==l&&t[p].r==R) +     { -t[p].val+=x; $t[p].lazy+=x; $         return ; -     } -     intMid= (T[P].L+T[P].R) >>1; the     if(l>mid) Change (p*2+1, l,r,x); -     Else if(r<=mid) Change (p*2, l,r,x);Wuyi     ElseChange (p*2, l,mid,x), Change (p*2+1, mid+1, r,x); theT[p].val=max (t[p*2].val,t[p*2+1].val); - } Wu  - intAskintPintLintR) About { $ Update (p); -     if(T[P].L==L&AMP;&AMP;T[P].R==R)returnT[p].val; -     intMid= (T[P].L+T[P].R) >>1; -     if(L>mid)returnAsk (p*2+1, l,r); A     Else if(R<=mid)returnAsk (p*2, l,r); +     Else returnMax (Ask (p*2, L,mid), Ask (p*2+1, mid+1, R)); the } -  $ intMain () the { thescanf"%d%d%d",&k,&n,&c); the      for(intI=1; i<=k;i++) thescanf"%d%d%d",&cow[i].f,&cow[i].t,&cow[i].sum); -Sort (cow+1, cow+1+k,cmp); inBuild1,1, n); the      for(intI=1; i<=k;i++) the     { About         intSta=ask (1, cow[i].f,cow[i].t), res=0; the         if(STA&GT;=C)Continue; the         if(sta+cow[i].sum<=c) res=cow[i].sum; the         Elseres=c-STA; +ans+=Res; -Change1, cow[i].f,cow[i].t-1, res); the     }Bayiprintf"%d", ans); the     return 0; the}
View Code

Luogu P1607 Temple Fair Shuttle "line Tree" by cellur925

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.