#include <bits/stdc++.h> using namespace std; #ifdef DEBUG auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << ", " << p.second << ")"; return o;} auto operator<<(auto &o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto e : x) o<<e<<", "; return o<<"}";} #define debug(X) cerr << "["#X"]: " << X << '\n'; #else #define cerr if(0)cout #define debug(X) ; #endif using ll = long long; #define all(v) (v).begin(), (v).end() #define ssize(x) int(x.size()) #define fi first #define se second #define mp make_pair #define eb emplace_back int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); map<int, int> m; for(int &x : a) { cin >> x; m[x]++; } debug(m); vector<int> res(n+1); for(auto &[x, cnt] : m) { for(int k = 1; k <= cnt; ++k) res[(cnt/k)]--; } debug(res); res[0] = n; for(int i = 1; i < n; ++i) res[i] += res[i-1]; for(int i = 1; i <= n; ++i) cout << res[i-1]*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 | #include <bits/stdc++.h> using namespace std; #ifdef DEBUG auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << ", " << p.second << ")"; return o;} auto operator<<(auto &o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto e : x) o<<e<<", "; return o<<"}";} #define debug(X) cerr << "["#X"]: " << X << '\n'; #else #define cerr if(0)cout #define debug(X) ; #endif using ll = long long; #define all(v) (v).begin(), (v).end() #define ssize(x) int(x.size()) #define fi first #define se second #define mp make_pair #define eb emplace_back int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); map<int, int> m; for(int &x : a) { cin >> x; m[x]++; } debug(m); vector<int> res(n+1); for(auto &[x, cnt] : m) { for(int k = 1; k <= cnt; ++k) res[(cnt/k)]--; } debug(res); res[0] = n; for(int i = 1; i < n; ++i) res[i] += res[i-1]; for(int i = 1; i <= n; ++i) cout << res[i-1]*i << ' '; return 0; } |