#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 10;
int a[maxn], ans[maxn];
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a + 1, a + n + 1);
vector<int> b;
int i = 1;
while (i <= n) {
int j = i;
while (j <= n && a[i] == a[j]) ++j; --j;
b.push_back(j - i + 1);
i = j + 1;
}
for (const auto& x : b) {
for (int i = 1; i <= x; ++i) {
ans[i] += x / i;
}
}
for (int i = 1; i <= n; ++i) {
if (i != 1) cout << " ";
cout << ans[i] * i;
}
cout << endl;
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 | #include <bits/stdc++.h> using namespace std; const int maxn = 300000 + 10; int a[maxn], ans[maxn]; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; sort(a + 1, a + n + 1); vector<int> b; int i = 1; while (i <= n) { int j = i; while (j <= n && a[i] == a[j]) ++j; --j; b.push_back(j - i + 1); i = j + 1; } for (const auto& x : b) { for (int i = 1; i <= x; ++i) { ans[i] += x / i; } } for (int i = 1; i <= n; ++i) { if (i != 1) cout << " "; cout << ans[i] * i; } cout << endl; return 0; } |
English