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