#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); i--) #define SZ(a) (int)a.size() #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair #define F first #define S second typedef long long LL; typedef vector<int> VI; typedef pair<int, int> PII; typedef double db; int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(15); int n; cin >> n; map<int, int> cnt; FOR(i, 0, n) { int x; cin >> x; cnt[x]++; } VI ans(n + 1, 0); for(auto [_, c] : cnt) { FOR(k, 1, c + 1) { ans[k] += k * (c / k); } } FOR(i, 1, n + 1) { if(i > 1) cout << " "; cout << ans[i]; } cout << "\n"; 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 | #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); i--) #define SZ(a) (int)a.size() #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair #define F first #define S second typedef long long LL; typedef vector<int> VI; typedef pair<int, int> PII; typedef double db; int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(15); int n; cin >> n; map<int, int> cnt; FOR(i, 0, n) { int x; cin >> x; cnt[x]++; } VI ans(n + 1, 0); for(auto [_, c] : cnt) { FOR(k, 1, c + 1) { ans[k] += k * (c / k); } } FOR(i, 1, n + 1) { if(i > 1) cout << " "; cout << ans[i]; } cout << "\n"; return 0; } |