#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
map<int, int> cnts;
for (int i = 0; i < n; i++) {
int v;
cin >> v;
cnts[v]++;
}
vector<int> res(n + 1);
for (auto it = cnts.begin(); it != cnts.end(); it++) {
int cnt = it->second;
int s = floor(sqrt(cnt));
int div = 1;
vector<array<int, 2>> vals;
vals.reserve(2 * s + 3);
vals.push_back({0, 0});
while (div <= s) {
vals.push_back({div, cnt / div});
div++;
}
int sz = vals.size();
for (int i = sz - 1; i > 0; i--) {
int a = vals[i][0];
int b = vals[i][1];
if (a == b) continue;
vals.push_back({b, a});
}
for (int i = 1; i < int(size(vals)); i++) {
res[vals[i - 1][0]] += vals[i][1];
res[vals[i][0]] -= vals[i][1];
}
}
for (int i = 1; i < n; i++) {
res[i] += res[i - 1];
}
for (int i = 0; i < n; i++) {
res[i] *= i + 1;
}
for (int i = 0; i < n; i++) {
cout << res[i] << " ";
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
// #ifdef LOCAL
// int t; cin >> t; while (t--)
// #endif
solve();
cout.flush();
}
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 | #include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; map<int, int> cnts; for (int i = 0; i < n; i++) { int v; cin >> v; cnts[v]++; } vector<int> res(n + 1); for (auto it = cnts.begin(); it != cnts.end(); it++) { int cnt = it->second; int s = floor(sqrt(cnt)); int div = 1; vector<array<int, 2>> vals; vals.reserve(2 * s + 3); vals.push_back({0, 0}); while (div <= s) { vals.push_back({div, cnt / div}); div++; } int sz = vals.size(); for (int i = sz - 1; i > 0; i--) { int a = vals[i][0]; int b = vals[i][1]; if (a == b) continue; vals.push_back({b, a}); } for (int i = 1; i < int(size(vals)); i++) { res[vals[i - 1][0]] += vals[i][1]; res[vals[i][0]] -= vals[i][1]; } } for (int i = 1; i < n; i++) { res[i] += res[i - 1]; } for (int i = 0; i < n; i++) { res[i] *= i + 1; } for (int i = 0; i < n; i++) { cout << res[i] << " "; } cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); // #ifdef LOCAL // int t; cin >> t; while (t--) // #endif solve(); cout.flush(); } |
English