Advertisement
dan_sml

Untitled

Jul 15th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define pii pair <int, int>
  3.  
  4. using namespace std;
  5.  
  6. signed main() {
  7.     int n;
  8.     vector <int> a;
  9.     vector <int> col;
  10.     multiset <pii> q;
  11.     cin >> n;
  12.     a.resize(n);
  13.     col.resize(n);
  14.     for (auto &x : a) cin >> x;
  15.     q.insert({a[0], 0});
  16.     int col_ = 1;
  17.     col[0] = col_;
  18.     for (int i = 1; i < n; i++) {
  19.         auto it = q.lower_bound({a[i], -i});
  20.         if (it == q.begin()) {
  21.             col_++;
  22.             col[i] = col_;
  23.         }
  24.         else {
  25.             it--;
  26.             col[i] = col[-(*it).second];
  27.             q.erase(*it);
  28.         }
  29.         q.insert({a[i], -i});
  30.     }
  31.     cout << col_ << "\n";
  32.     for (auto x : col) cout << x << " ";
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement