HDU 1698 Just a Hook

Source: Internet
Author: User

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

Related Article

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.