#include <bits/stdc++.h>
#define boost \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
const int MAX_N = 300'005;
int ans[MAX_N];
int32_t main() {
boost;
int n;
cin >> n;
map<int, int> cnt;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
cnt[x]++;
}
for (auto [_, c] : cnt) {
for (int i = 1; i <= c; i++) {
ans[i] += (c / i) * i;
}
}
for (int i = 1; i <= n; i++) cout << ans[i] << " ";
cout << "\n";
}
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 | #include <bits/stdc++.h> #define boost \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define ALL(x) (x).begin(), (x).end() using namespace std; const int MAX_N = 300'005; int ans[MAX_N]; int32_t main() { boost; int n; cin >> n; map<int, int> cnt; for (int i = 1; i <= n; i++) { int x; cin >> x; cnt[x]++; } for (auto [_, c] : cnt) { for (int i = 1; i <= c; i++) { ans[i] += (c / i) * i; } } for (int i = 1; i <= n; i++) cout << ans[i] << " "; cout << "\n"; } |
English