#include <iostream> #include <algorithm> #include <map> #include <vector> using namespace std; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n; cin >> n; // n = 300000; map<int, int> freq; int x, m = 0; for (int i = 0; i < n; ++i) { cin >> x; // if (x < 30000) { // x = i; // } else { // x = 0; // } freq[x]++; if (m < freq[x]) { m = freq[x]; } } vector<int> f(freq.size()); int a = 0; for (const auto& [k, v] : freq) { f[a] = v; a++; } sort(f.begin(), f.end(), greater<>()); int i = 1; while (i <= m) { int ri = 0; for (const auto& v : f) { ri += (v / i) * i; if (v / i == 0) { break; } } ++i; cout << ri << " "; } while (i <= n) { cout << "0 "; ++i; } cout << "\n"; 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 55 56 57 58 59 60 61 62 | #include <iostream> #include <algorithm> #include <map> #include <vector> using namespace std; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n; cin >> n; // n = 300000; map<int, int> freq; int x, m = 0; for (int i = 0; i < n; ++i) { cin >> x; // if (x < 30000) { // x = i; // } else { // x = 0; // } freq[x]++; if (m < freq[x]) { m = freq[x]; } } vector<int> f(freq.size()); int a = 0; for (const auto& [k, v] : freq) { f[a] = v; a++; } sort(f.begin(), f.end(), greater<>()); int i = 1; while (i <= m) { int ri = 0; for (const auto& v : f) { ri += (v / i) * i; if (v / i == 0) { break; } } ++i; cout << ri << " "; } while (i <= n) { cout << "0 "; ++i; } cout << "\n"; return 0; } |