POJ-2828-Buy tickets
Http://poj.org/problem? Id = 2828
Line Segment tree, reverse insertion
# include
# include
# include
# include
using namespace STD; # define n 200010 struct cam {int X, Y; int num;} list [N * 8]; int POS [N], value [N], ANS [N]; int N; void build (int K, int X, int y) // The number of seats not occupied in the storage interval of the Line Segment tree {list [K]. X = x; list [K]. y = y; list [K]. num = (Y-x + 1); If (x = y) return; int mid; Mid = (x + y)/2; build (k <1, x, mid); Build (k <1 | 1, Mid + 1, Y);} void find (int K, int POs, I NT value) {list [K]. num --; If (list [K]. X = list [K]. y) {ans [list [K]. x] = value; return;} If (list [k <1]. num> = POS) Find (k <1, POs, value); elsefind (k <1 | 1, pos-list [k <1]. num, value) ;}int main () {int I; while (scanf ("% d", & N )! = EOF) {for (I = 1; I <= N; I ++) scanf ("% d", & Pos [I], & value [I]); Build (1, 1, n); for (I = N; I> = 1; I --) Find (1, POS [I] + 1, value [I]); for (I = 1; I <= N; I ++) {if (I = N) printf ("% d \ n ", ans [I]); elseprintf ("% d", ANS [I]) ;}} return 0 ;}