#include<bits/stdc++.h> using namespace std; unordered_map<int, int> umap; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> ot(n+1, 0); for(int i=0, a; i<n; ++i){ cin >> a; auto it = umap.find(a); if(it == umap.end()){ umap[a] = 1; }else{ (it->second)++; } } for(auto it = umap.begin(); it != umap.end(); ++it){ int i=1; while((it->second)/i > 0){ ot[i]+= ((it->second)/i)*i; i++; } } for(int i=1; i<=n; ++i) cout << ot[i] << " "; }
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 | #include<bits/stdc++.h> using namespace std; unordered_map<int, int> umap; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> ot(n+1, 0); for(int i=0, a; i<n; ++i){ cin >> a; auto it = umap.find(a); if(it == umap.end()){ umap[a] = 1; }else{ (it->second)++; } } for(auto it = umap.begin(); it != umap.end(); ++it){ int i=1; while((it->second)/i > 0){ ot[i]+= ((it->second)/i)*i; i++; } } for(int i=1; i<=n; ++i) cout << ot[i] << " "; } |