SDUTOJ2880 devour Magic (segment tree dual delay marker)

Source: Internet
Author: User

Test instructions

Each point energy plus 1 per second

Give you a chronological order. N Group Time + interval

Represents the energy within the interval at time t.

Ask how much energy was taken away

Ideas:

Interval Modification interval Query

Increase the number of energy delay

I'll delay it after we go.

Save delay status with two flags

/************************************************author:d evilcreated TIME:2016/5/14 17:23:34***************** ******************************* */#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<cmath>#include<stdlib.h>using namespacestd;Const intn=1e5+7;Long Longtree[n<<2];BOOLflag[n<<2],flag2[n<<2];intdone[n<<2];voidPUSHDOWN2 (intNodeintLintR) {Flag2[node]=0; Flag[node]=0; Tree[node]=0; Done[node]=0; if(L==R)return ; intM= (l+r) >>1; Tree[node<<1]=0; Flag2[node<<1]=1; Tree[node<<1|1]=0; Flag2[node<<1|1]=1;}voidPushdown (intNodeintLintR) {    if(Flag2[node]) pushdown2 (NODE,L,R); Flag[node]=0; if(L==R)return ; intM= (l+r) >>1; if(flag2[node<<1]) Pushdown2 (node<<1, l,m); Tree[node<<1]+= (m-l+1)*Done[node]; Flag[node<<1]=1; Done[node<<1]+=Done[node]; if(flag2[node<<1|1]) Pushdown2 (node<<1|1, m+1, R); Tree[node<<1|1]+= (R-M) *Done[node]; Flag[node<<1|1]=1; Done[node<<1|1]+=Done[node]; //printf ("%d%d%d%d\n", L,r,tree[node<<1],tree[node<<1|1],done[node]);done[node]=0;}voidUpdateintNodeintLintRintadd) {    if(Flag2[node]) pushdown2 (NODE,L,R); Flag[node]=1; Done[node]+=add; Tree[node]+ = (r-l+1)*add;}Long LongQueryintNodeintLintRintXinty) {    if(l>=x&&r<=y) {Flag2[node]=1; Long Longtmp=Tree[node]; Tree[node]=0; //printf ("%d%d%d\n", L,r,tree[node]);        returntmp; }    if(Flag2[node]) pushdown2 (NODE,L,R); if(Flag[node]) pushdown (NODE,L,R); intM= (l+r) >>1, ans=0; if(x<=m) Ans+=query (node<<1, L,m,x,y); if(y>m) Ans+=query (node<<1|1, m+1, R,x,y); Tree[node]=tree[node<<1]+tree[node<<1|1]; returnans;}intMain () {//freopen ("In.txt", "R", stdin);    intT; scanf ("%d",&t);  while(t--)    {        intn,m,s,x,y,now=0; Long Longans=0; scanf ("%d%d",&n,&m); memset (Tree,0,sizeof(tree)); memset (Done,0,sizeof(done)); memset (Flag,0,sizeof(flag)); memset (Flag2,0,sizeof(Flag2));  while(m--) {scanf ("%d%d%d",&s,&x,&y); Update (1,1, n,s-Now ); now=s; Ans+=query (1,1, N,x,y); } printf ("%lld\n", ans); }    return 0;}

SDUTOJ2880 devour Magic (segment tree dual delay marker)

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.