#include <bits/stdc++.h> using namespace std; #define maxn 300010 unordered_map<int, int> cnt; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n,x; cin >> n; for (int i = 0; i < n; ++i) { cin >> x; cnt[x]++; } int res = n; for (int i = 1; i <= n; ++i) { int tmp = res; vector<int> removed; for (auto it = cnt.begin(); it != cnt.end(); ++it) { tmp -= it->second % i; if (it->second == i) { removed.push_back(it->first); res -= i; } } for (auto x : removed) { cnt.erase(x); } cout << tmp << ((i != 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 31 32 33 34 | #include <bits/stdc++.h> using namespace std; #define maxn 300010 unordered_map<int, int> cnt; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n,x; cin >> n; for (int i = 0; i < n; ++i) { cin >> x; cnt[x]++; } int res = n; for (int i = 1; i <= n; ++i) { int tmp = res; vector<int> removed; for (auto it = cnt.begin(); it != cnt.end(); ++it) { tmp -= it->second % i; if (it->second == i) { removed.push_back(it->first); res -= i; } } for (auto x : removed) { cnt.erase(x); } cout << tmp << ((i != n) ? " " : ""); } } |