Inverted plug, do not understand the meaning, and then read a puzzle to say simulation
A manual simulation is a good idea-----
But the words have been written down---always changed-----
Good-hearted stuffed------
1#include <cstdio>2#include <ctime>3#include <cstring>4#include <cstdlib>5#include <cmath>6#include <vector>7#include <map>8#include <Set>9#include <stack>Ten#include <queue> One#include <string> A#include <iostream> -#include <algorithm> - using namespacestd; the - #defineGetmid (L,r) ((L) + ((r)-(L))/2) - -typedefLong LongLL; + Const DoubleEPS = 1e-8; - Const intINF = (1<< -) -1; + Const intMAXN =200005; A at structnode{ - intl,r,s; -}t[4*MAXN]; - - structedge{ - intPos,val; in }A[MAXN]; - to intN; + intANS[MAXN]; - the voidPUSH_UP (intp) { *T[P].S = t[p<<1].s + t[p<<1|1].s; $ }Panax Notoginseng - the voidBuild_tree (intPintLintR) { +T[P].L =l; AT[P].R =R; the if(L = =R) { +T[P].S =1; - return; $ } $ intMID =Getmid (l,r); -Build_tree (p<<1, l,mid); -Build_tree (p<<1|1, mid+1, R); the push_up (p); - }Wuyi the voidUpdateintIdxintp) { - if(T[P].L = =T[P].R) { Wut[p].s--; - return; About } $ intMID =Getmid (T[P].L,T[P].R); - if(IDX <= mid) update (idx,p<<1); - ElseUpdate (idx,p<<1|1); - push_up (p); A } + the intQueryintIdxintp) { - if(T[P].L = = T[P].R)returnT[P].L; $ if(t[p<<1].S >= idx)returnQuery (idx,p<<1); the Else returnQuery (idx-t[p<<1].s,p<<1|1); the } the the voidsolve () { -Build_tree (1,1, n); in //for (int i = 1;i <= 2*n;i++) the //printf ("t[%d].l =%d T[%D].R =%d T[%d].s =%d\n", i,t[i].l,i,t[i].r,i,t[i].s); the for(inti = N;i >=1; i--){ About intpos =A[i].pos; the intid = query (pos,1); theAns[id] =A[i].val; theUpdate (ID,1); + } -printf"%d", ans[1]); the for(inti =2; I <= n;i++) printf ("%d", Ans[i]);Bayiprintf"\ n"); the } the - intMain () { - while(SCANF ("%d", &n)! =EOF) { the for(inti =1; I <= n;i++){ thescanf"%d%d",&a[i].pos,&a[i].val); thea[i].pos++; the } - solve (); the } the return 0; the}
View Code
Come on, ~ ~ ~
POJ 2828 Buy Tickets "segment Tree single point Update"