#include <bits/stdc++.h>
using namespace std;
#define FOR(i, lower, upper) for(int (i) = (lower); i <= (int)(upper); (i)++)
#define FORD(i, upper, lower) for(int (i) = (upper); i >= (int)(lower); (i)--)
const int N = 3e5;
//vector<int> a;
//unordered_set<int> s;
unordered_map<int, int> cnt;
int ans[N + 1];
int n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
FOR(i, 1, n) {
int x;
cin >> x;
//s.insert(x);
cnt[x]++;
}
// sort(a + 1, a + 1 + n);
// int M = 1;
// FOR(i, 2, n) {
// if(i != 2 && a[i] != a[i - 1]) {
// a[i - 1] = M;
// M++;
// }
// else {
// a[i - 1] = M;
// }
// }
// a[n] = M;
// FOR(i, 1, n) {
// cnt[a[i]]++;
// }
// FOR(i, 1, M) {
// FOR(j, 1, cnt[i]) {
// ans[j] += (cnt[i] / j) * j;
// }
// }
for(pair<int, int> p : cnt) {
FOR(i, 1, p.second) {
ans[i] += (p.second / i) * i;
}
}
FOR(i, 1, n) {
cout << ans[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 | #include <bits/stdc++.h> using namespace std; #define FOR(i, lower, upper) for(int (i) = (lower); i <= (int)(upper); (i)++) #define FORD(i, upper, lower) for(int (i) = (upper); i >= (int)(lower); (i)--) const int N = 3e5; //vector<int> a; //unordered_set<int> s; unordered_map<int, int> cnt; int ans[N + 1]; int n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; FOR(i, 1, n) { int x; cin >> x; //s.insert(x); cnt[x]++; } // sort(a + 1, a + 1 + n); // int M = 1; // FOR(i, 2, n) { // if(i != 2 && a[i] != a[i - 1]) { // a[i - 1] = M; // M++; // } // else { // a[i - 1] = M; // } // } // a[n] = M; // FOR(i, 1, n) { // cnt[a[i]]++; // } // FOR(i, 1, M) { // FOR(j, 1, cnt[i]) { // ans[j] += (cnt[i] / j) * j; // } // } for(pair<int, int> p : cnt) { FOR(i, 1, p.second) { ans[i] += (p.second / i) * i; } } FOR(i, 1, n) { cout << ans[i] << ' '; } return 0; } |
English