#include <iostream> #include <unordered_map> #include <vector> #include <algorithm> using namespace std; int tab[300007]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); int n, x; cin >> n; vector<int> cities(n); unordered_map<int, int> cityCount; unordered_map<int, int> cityCount2; vector<pair<int, int> > pairs; for (int i = 0; i < n; ++i) { cin >> x; cityCount[x]++; } for(auto it = cityCount.begin(); it!=cityCount.end();it++){ cityCount2[it->second]++; } for(auto it = cityCount2.begin(); it!=cityCount2.end();it++){ pairs.push_back({-it->first, it->second}); } sort(pairs.begin(), pairs.end()); for(int i=0;i<n;i++){ int odp = 0; for(int j=0;j<pairs.size();j++){ if(i+1>-pairs[j].first){ break; } else{ odp += -(pairs[j].first / (i+1))* (i+1) * pairs[j].second; } } cout<<odp<<" "; } 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 | #include <iostream> #include <unordered_map> #include <vector> #include <algorithm> using namespace std; int tab[300007]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); int n, x; cin >> n; vector<int> cities(n); unordered_map<int, int> cityCount; unordered_map<int, int> cityCount2; vector<pair<int, int> > pairs; for (int i = 0; i < n; ++i) { cin >> x; cityCount[x]++; } for(auto it = cityCount.begin(); it!=cityCount.end();it++){ cityCount2[it->second]++; } for(auto it = cityCount2.begin(); it!=cityCount2.end();it++){ pairs.push_back({-it->first, it->second}); } sort(pairs.begin(), pairs.end()); for(int i=0;i<n;i++){ int odp = 0; for(int j=0;j<pairs.size();j++){ if(i+1>-pairs[j].first){ break; } else{ odp += -(pairs[j].first / (i+1))* (i+1) * pairs[j].second; } } cout<<odp<<" "; } return 0; } |