Segment tree, interval modification, interval and
To turn an interval into a value
/************************************************author:zhou zhentaoemail: [Email protected]created Tim E:2015/11/20 17:21:35file name:acm.cpp*************************************************/#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<time.h>using namespacestd;#defineLson L, M, RT << 1#defineRson m + 1, R, RT << 1 | 1#defineRoot 1, N, 1#defineLL Long LongConst intMAXN =100000+Ten; LL ADD[MAXN<<2]; LL SUM[MAXN<<2]; voidPushup (intRT) {Sum[rt]= sum[rt<<1] + sum[rt<<1|1]; } voidPushdown (intRtintm) {if(Add[rt]) {add[rt<<1] =Add[rt]; Add[rt<<1|1] =Add[rt]; Sum[rt<<1] = add[rt] * (M-(M >>1)); Sum[rt<<1|1] = add[rt] * (M >>1); ADD[RT]=0; } } voidBuildintLintRintRT) {Add[rt]=0; if(L = =r) {//scanf ("%lld", &sum[rt]); sum[rt]=1; return ; } intm = (L + r) >>1; Build (Lson); Build (Rson); Pushup (RT); } voidUpdateintLintRintCintLintRintRT) { if(l <= l && R <=R) {Add[rt]=C; SUM[RT]= (LL) c * (R-l +1); return ; } pushdown (RT, R-L +1); intm = (L + r) >>1; if(L <=m) Update (L, R, C, Lson); if(M <r) Update (L, R, C, Rson); Pushup (RT); } LL Query (intLintRintLintRintRT) { if(l <= l && R <=R) {returnSum[rt]; } pushdown (RT, R-L +1); intm = (L + r) >>1; LL ret=0; if(L <= m) ret + =query (L, R, Lson); if(M < R) ret + =query (L, R, Rson); returnret; } intMain () {intN, q,t; scanf ("%d",&T); for(intCase=1; case<=t; case++) {memset (Add,0,sizeofadd); memset (SUM,0,sizeofsum); scanf ("%d",&N); Build (root); scanf ("%d",&p); while(q--) { intL,r,c; scanf ("%d%d%d",&l,&r,&b); Update (L,R,C,ROOT); } intAns=query (1, N,root); printf ("Case%d:the Total value of the hook is%d.\n", Case,ans); } return 0; }
HDU 1698 Just a Hook