Buy Tickets POJ - 2828 (tree line, single-point update, query interval)

Topic links: https://i-beta.cnblogs.com/posts/edit

Idea: consider the opposite of the input data, then the location of the input x x individual on his behalf has existed before,

But later people will jump the queue, then there is already a person can be expressed as x, there should be in front of several vacancies.

Because we are the inverse relationship between the traverse position, then we only need to maintain in front of the array can have x number of vacancies.

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <map>
 4 #include <queue>
 5 #include <string>
 6 #include <stack>
 7 #include <vector>
 8 #include <list>
 9 #include <cstdio>
10 #include <cstring>
11 #include <cmath>
12 using namespace std;
13 #define ll long long
14 #define pb push_back
15 #define fi first
16 #define se second
17 #define lson(x) x<<1
18 #define rson(x) x<<1|1
19 
20 
21 const int N = 2e5+10;
22 struct node{
23     int l,r,blank;
24     int mid(){ return (l+r)>>1; }
25 }tree[N<<2];
26 int inx[N],v[N],que[N];
27 int n,tim;
28 
29 void build_tree(int rt, int l_b, int r_b){
30      Tree [RT] .L = L_B; Tree [RT] .r = r_B;
 31 is      IF (L_B == r_B) {
 32          Tree [RT] = .blank . 1 ; // . 1 representative of a location 
33 is          return ;
 34 is      }
 35      int MID = Tree [RT] .mid ();
 36      build_tree (LSON (RT), L_B, MID);
 37 [      build_tree (rson (RT), + MID . 1 , r_B);
 38 is      Tree [RT] = Tree .blank [LSON (RT)] + blank. Tree [rson (RT)] blank;.
 39  }
 40  
41 is  // subtract position 
42 is  void Update (int X) {
 43 is      the while (X =! . 1 ) {
 44 is          Tree [X] .blank - = . 1 ;
 45          X = >> . 1 ;
 46 is      }
 47  }
 48  
49  // find this location 
50  void Search ( int RT, int TOT, int V) {
 51 is      IF (Tree [RT] .L == Tree [RT] .r) {
 52 is          que [Tree [RT] .L] = V;  
 53 is          Update (RT);
 54 is          return ;
 55      }
 56 is     // this position on the left 
57 is      IF (Tree [LSON (RT)] blank> =. TOT) Search (LSON (RT), TOT, V);
 58      // this position on the right side 
59      the else Search (rson (RT), TOT - Tree [LSON (RT)] blank, V);.
 60      
61 is  }
 62 is  
63 is  void Solve () {
 64      the while (~ Scanf ( " % D " &, n-)) {
 65          Tim = 0 ;
 66          build_tree ( . 1 , . 1 , n-);
 67          for ( int I = . 1 ; I <= n-; I ++) Scanf ("%d%d", inx+i, v+i);
68         for(int i = n; i >= 1; --i){
69             search(1, inx[i]+1, v[i]);
70         }
71         printf("%d", que[1]);
72         for(int i = 2; i <= n; ++i){
73             printf(" %d", que[i]);
74         }
75         printf("\n");
76     }
77 }
78 
79 int main(){
80  
81   //  ios::sync_with_stdio(false);
82   //  cin.tie(0); cout.tie(0);
83     solve();
84 
85     return 0;
86 }

 

              

Guess you like

Origin www.cnblogs.com/SSummerZzz/p/12552478.html