Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  9.  
  10. int main() {
  11.     ios_base::sync_with_stdio(false); cin.tie(0);
  12.  
  13.     int n;
  14.     cin >> n;
  15.     vector< vector<int> > st(n + 1);
  16.     vector< vector<int> > fin(n + 1);
  17.     for (int i = 0; i < n; i++) {
  18.         int a, b;
  19.         cin >> a >> b;
  20.         st[a].push_back(i);
  21.         fin[b].push_back(i);
  22.     }
  23.  
  24.     ordered_set d;
  25.     for (int k = 1; k <= n; k++) {
  26.         for (auto i: st[k]) d.insert(i);
  27.         if (d.size() < k) {
  28.             cout << -1 << ' ';
  29.         } else {
  30.             cout << *d.find_by_order(k - 1) + 1 << ' ';
  31.         }
  32.         for (auto i: fin[k]) d.erase(i);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement