POJ-2828-Buy tickets

Source: Internet
Author: User

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 ;}
     
    
   
  

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.