"The main topic"
Query the left-most continuous length interval, or batch modify some intervals.
Ideas
Interval Merge segment tree ... Review it. POJ on the same topic, I actually borrowed someone else's permission number to do Bzoj, simply ignorant to no friends [laughter cry]
Processing methods in the previous blog post, there is no more to repeat.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cstdlib>6 using namespacestd;7 #defineLson l,m,rt<<18 #defineRson m+1,r,rt<<1|19 Const intmaxn=55555+Ten;Ten intcover[maxn<<2];//-1 means that there is currently no overwrite tag, 1 means that all overrides are not feasible, and 0 means that all overrides are feasible One intlsum[maxn<<2];//the maximum number of consecutive interval lengths from left to the interval A intmsum[maxn<<2];//The maximum number of consecutive available interval lengths in this interval - intrsum[maxn<<2];//the maximum number of consecutive available interval lengths for the interval from right up - the voidPushup (intRtintm) - { -lsum[rt]=lsum[rt<<1]; - if(Lsum[rt]==m-(m>>1)) lsum[rt]+=lsum[rt<<1|1]; +rsum[rt]=rsum[rt<<1|1]; - if(rsum[rt]==m>>1) rsum[rt]+=rsum[rt<<1]; +Msum[rt]=max (Max (msum[rt<<1],msum[rt<<1|1]), rsum[rt<<1]+lsum[rt<<1|1]); A } at - voidPushdown (intRtintm) - { - if(cover[rt]!=-1) - { -cover[rt<<1]=cover[rt<<1|1]=Cover[rt]; in if(cover[rt]==1) - { tomsum[rt<<1]=lsum[rt<<1]=rsum[rt<<1]=0; +msum[rt<<1|1]=lsum[rt<<1|1]=rsum[rt<<1|1]=0; - } the Else * { $msum[rt<<1]=lsum[rt<<1]=rsum[rt<<1]=m-(m>>1);Panax Notoginsengmsum[rt<<1|1]=lsum[rt<<1|1]=rsum[rt<<1|1]=m>>1; - } thecover[rt]=-1; + } A } the + - intQueryintWintLintRintRT) $ { $ if(L==R)returnl; -Pushdown (rt,r-l+1); - intM= (l+r) >>1; the if(msum[rt<<1]>=W)return(Query (W,lson)); - if(rsum[rt<<1]+lsum[rt<<1|1]>=W)return(m-rsum[rt<<1]+1);Wuyi if(msum[rt<<1|1]>=W)return(Query (W,rson)); the return 0; - } Wu - voidUpdateintLintRintOintLintRintRT) About { $ if(L<=l && r<=R) - { -cover[rt]=o; - if(o==1) msum[rt]=lsum[rt]=rsum[rt]=0; A Elsemsum[rt]=lsum[rt]=rsum[rt]=r-l+1; + return; the } -Pushdown (rt,r-l+1);//this is L and R, don't write L and R. $ intM= (l+r) >>1; the if(l<=m) update (L,r,o,lson); the if(m<R) Update (L,r,o,rson); thePushup (rt,r-l+1); the } - in voidBuildintLintRintRT) the { themsum[rt]=lsum[rt]=rsum[rt]=r-l+1; Aboutcover[rt]=-1; the if(L==R)return; the intM= (l+r) >>1; the build (Lson); + build (Rson); - } the Bayi intMain () the { the intn,m; -scanf"%d%d",&n,&m); -Build1N1); the for(intI=0; i<m;i++) the { the intop; thescanf"%d",&op); - if(op==1) the { the intW; thescanf"%d",&W);94 if(msum[1]<W) cout<<0<<Endl; the Else the { the intP=query (W,1N1);98cout<<p<<Endl; AboutUpdate (p,p+w-1,1,1N1); - }101 }102 Else103 {104 intu,v; thescanf"%d%d",&u,&v);106Update (u,u+v-1,0,1N1);107 }108 }109 return 0; the}
"Interval Merge segment tree" bzoj1593-accommodation arrangement