Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem: E. MEX and Increments
- // Contest: Codeforces - Codeforces Round 762 (Div. 3)
- // URL: https://codeforces.com/problemset/problem/1619/E
- // Memory Limit: 256 MB
- // Time Limit: 2000 ms
- //
- // Powered by CP Editor (https://cpeditor.org)
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #ifndef __DEBUG__
- #define dbg(...) 42
- #endif
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using a2l = array<ll, 2>;
- using pll = pair<ll, ll>;
- using vl = vector<ll>;
- void solve()
- {
- ll n, mex = 0;
- cin >> n;
- vl a(n), cnt(n + 1);
- for (auto &x : a) {
- cin >> x;
- if (x <= n)
- cnt[x] += 1;
- }
- while (mex <= n && cnt[mex])
- ++mex;
- vl ans(n + 1, -1);
- map<ll, ll> opt;
- for (ll i = 0; i < mex; ++i) {
- ans[i] = cnt[i];
- if (cnt[i] > 1)
- opt[i] = cnt[i] - 1;
- }
- ans[mex] = 0;
- for (ll i = mex + 1, acc = 0; i <= n; ++i) {
- dbg(opt);
- if (opt.size() == 0) {
- break;
- }
- auto [k, v] = *opt.rbegin();
- acc += i - 1 - k;
- if (v == 1)
- opt.erase(k);
- else
- opt[k] -= 1;
- ans[i] = acc + cnt[i];
- if (cnt[i])
- opt[i] = cnt[i];
- }
- for (auto x : ans)
- cout << x << ' ';
- cout << '\n';
- }
- int main(int argc, char **argv)
- {
- ll t;
- cin >> t;
- while (t--)
- solve();
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement