#include <bits/stdc++.h> #define MAX_N 300007 using namespace std; int n, k; map<int, int> map_k; map<int, int> map_c; queue<pair<int, int>> q_c; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> k; if (map_k.contains(k)) { map_k[k]++; } else { map_k[k] = 1; } } for (auto p : map_k) { // cout << p.first << " " << p.second << "\n"; if (map_c.contains(p.second)) { map_c[p.second]++; } else { map_c[p.second] = 1; } } for (auto p : map_c) { q_c.push(p); } for (int i = 1; i <= n; i++) { int qs = q_c.size(); int res = 0; for (int j = 0; j < qs; j++) { pair<int, int> p = q_c.front(); q_c.pop(); if (p.first >= i) { res += (p.first / i) * i * p.second; q_c.push(p); } } cout << res << " "; } 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> #define MAX_N 300007 using namespace std; int n, k; map<int, int> map_k; map<int, int> map_c; queue<pair<int, int>> q_c; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> k; if (map_k.contains(k)) { map_k[k]++; } else { map_k[k] = 1; } } for (auto p : map_k) { // cout << p.first << " " << p.second << "\n"; if (map_c.contains(p.second)) { map_c[p.second]++; } else { map_c[p.second] = 1; } } for (auto p : map_c) { q_c.push(p); } for (int i = 1; i <= n; i++) { int qs = q_c.size(); int res = 0; for (int j = 0; j < qs; j++) { pair<int, int> p = q_c.front(); q_c.pop(); if (p.first >= i) { res += (p.first / i) * i * p.second; q_c.push(p); } } cout << res << " "; } return 0; } |