Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pii pair <int, int>
- using namespace std;
- signed main() {
- int n;
- vector <int> a;
- vector <int> col;
- multiset <pii> q;
- cin >> n;
- a.resize(n);
- col.resize(n);
- for (auto &x : a) cin >> x;
- q.insert({a[0], 0});
- int col_ = 1;
- col[0] = col_;
- for (int i = 1; i < n; i++) {
- auto it = q.lower_bound({a[i], -i});
- if (it == q.begin()) {
- col_++;
- col[i] = col_;
- }
- else {
- it--;
- col[i] = col[-(*it).second];
- q.erase(*it);
- }
- q.insert({a[i], -i});
- }
- cout << col_ << "\n";
- for (auto x : col) cout << x << " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement