Naxocist

toi19_range

Jun 15th, 2023
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using T = tuple<int, int, int>;
  5.  
  6. int main() {
  7.     cin.tie(nullptr)->sync_with_stdio(false);
  8.     int n; cin >> n;
  9.     vector<T> v(n);
  10.     for(int i=0; i<n; ++i) {
  11.         int l, r; cin >> l >> r;
  12.         v[i] = T(r, -l, i);
  13.     }
  14.     sort(v.begin(), v.end());
  15.  
  16.     vector<int> lis, res(n);
  17.     for(auto &x : v) {
  18.         int l, r, i; tie(r, l, i) = x;
  19.  
  20.         auto t = upper_bound(lis.begin(), lis.end(), l);
  21.         if(t == lis.end()) {
  22.             lis.push_back(l);
  23.             res[i] = lis.size();
  24.         }else {
  25.             *t = l;
  26.             res[i] = t - lis.begin() + 1;
  27.         }
  28.     }
  29.     cout << lis.size() << '\n';
  30.     for(auto &x : res) {
  31.         cout << x << ' ';
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment