POJ 2828 segment Tree Jack processing

Source: Internet
Author: User

I'll give you a sequence number. num "i" and the corresponding numerical value output the corresponding value of the final sequence, such as

40 771 511) 332 69
First Step

Part II 77 51

Step three 77 33 51

Part fourth 77 33 69 51

The position that appears after the first is fixed, so it is processed from the back. The number of slots in each node of the segment tree that is stored in the current interval;


#include<stdio.h>#include<string.h>#include<iostream>using namespaceStd;#define LL(X) (X<<1)#define RR(X) ((X<<1)|1)struct node {intCont;}Tree[4*200000];intNum[200010][3],Queue[200010];int deal(intL,intR,intPoint){Tree[Point].Cont=R-L+1;if(L==R)return 0;intMid=(L+R)/2;deal(L,Mid,LL(Point));deal(Mid+1,R,RR(Point));return 0; }int Update(intL,intR,intPos,intPoint,intValue){Tree[Point].Cont--;if(L==R){Queue[L]=Value;return 0;}intMid=(L+R)/2;if(Pos<=Tree[LL(Point)].Cont) Update(L,Mid,Pos,LL(Point),Value);Else Update(Mid+1,R,Pos-Tree[LL(Point)].Cont,RR(Point),Value);return 0;}int Main(){intN,I,J; while(~scanf("%d",&N)){deal(1,N,1); for(I=1;I<=N;I++){scanf("%d%d",&Num[I][1],&Num[I][2]);Num[I][1]++;} for(I=N;I>=1;I--){   Update(1,N,Num[I][1],1,Num[I][2]);} for(I=1;I<=N;I++){if(I!=1) printf(" ");printf("%d",Queue[I]);}printf("\ n");}return 0;}


POJ 2828 segment Tree Jack processing

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.