#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, j) for (int i = 0; i < (int)(j); i++) #define st first #define nd second void TEST([[maybe_unused]] int testcase_i) { int n; cin >> n; map<int, int> counter; rep(i, n) { int x; cin >> x; counter[x]++; } vector<int> ans(n + 1); for (auto [_, val] : counter) { int prv = 0; int ppl = 1; int give = val; while (true) { ans[prv] -= give; ans[ppl] += give; prv = ppl; give = min(val / (ppl + 1), give - 1); if (give == 0) { break; } ppl = val / give; give = val / ppl; } } for (int i = n - 1; i > 0; i--) { ans[i] += ans[i + 1]; } rep(i, n) { cout << ans[i + 1] * (i + 1) << " "; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << setprecision(20) << fixed; // srand(time(NULL)); int t = 1; // cin >> t; rep(i, t) { TEST(i); } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, j) for (int i = 0; i < (int)(j); i++) #define st first #define nd second void TEST([[maybe_unused]] int testcase_i) { int n; cin >> n; map<int, int> counter; rep(i, n) { int x; cin >> x; counter[x]++; } vector<int> ans(n + 1); for (auto [_, val] : counter) { int prv = 0; int ppl = 1; int give = val; while (true) { ans[prv] -= give; ans[ppl] += give; prv = ppl; give = min(val / (ppl + 1), give - 1); if (give == 0) { break; } ppl = val / give; give = val / ppl; } } for (int i = n - 1; i > 0; i--) { ans[i] += ans[i + 1]; } rep(i, n) { cout << ans[i + 1] * (i + 1) << " "; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << setprecision(20) << fixed; // srand(time(NULL)); int t = 1; // cin >> t; rep(i, t) { TEST(i); } return 0; } |