#include <cassert> #include <iostream> #include <istream> #include <fstream> #include <algorithm> #include <cstdio> #include <complex> #include <vector> #include <set> #include <map> #include <cmath> #include <queue> #include <string> #include <cstdlib> #include <memory> #include <ctime> #include <bitset> #include <queue> #include <stack> #include <unordered_map> #include <unordered_set> #include <bitset> #include <ranges> using namespace std; class Zna2024 { long n; vector<long> input; public: void virtual Solve() { cin >> n; input = vector<long>(n, 0); //set<int> set; map<long, long> map; for (int i = 0; i < n; i++) { cin >> input[i]; } for (int i = 0; i < n; i++) { int elem_i = input[i]; //set.insert(elem_i); if (map.find(elem_i) == map.end()) { map[elem_i] = 1; } else { map[elem_i]++; } } //long total = 0; long res = 0; long max = 0; vector<long> vec; for (const auto& pair : map) { vec.push_back(pair.second); max = std::max(pair.second, max); } std::sort(vec.begin(), vec.end(), std::greater<long>()); vector<long> result = vector<long>(n, 0); int all = map.size(); for (int k = 1; k <= max; k++) { long value = 0; for (int m = 0; m < all; m++) { if (vec[m] / k >= 1) { value += ((vec[m] / k) * k); } else { break; } } result[k-1] = value; } for (int i = 0; i < n; i++) { if (i > 0) { std::cout << " "; } std::cout << result[i]; } } }; int main() { Zna2024* p = new Zna2024(); p->Solve(); delete p; 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | #include <cassert> #include <iostream> #include <istream> #include <fstream> #include <algorithm> #include <cstdio> #include <complex> #include <vector> #include <set> #include <map> #include <cmath> #include <queue> #include <string> #include <cstdlib> #include <memory> #include <ctime> #include <bitset> #include <queue> #include <stack> #include <unordered_map> #include <unordered_set> #include <bitset> #include <ranges> using namespace std; class Zna2024 { long n; vector<long> input; public: void virtual Solve() { cin >> n; input = vector<long>(n, 0); //set<int> set; map<long, long> map; for (int i = 0; i < n; i++) { cin >> input[i]; } for (int i = 0; i < n; i++) { int elem_i = input[i]; //set.insert(elem_i); if (map.find(elem_i) == map.end()) { map[elem_i] = 1; } else { map[elem_i]++; } } //long total = 0; long res = 0; long max = 0; vector<long> vec; for (const auto& pair : map) { vec.push_back(pair.second); max = std::max(pair.second, max); } std::sort(vec.begin(), vec.end(), std::greater<long>()); vector<long> result = vector<long>(n, 0); int all = map.size(); for (int k = 1; k <= max; k++) { long value = 0; for (int m = 0; m < all; m++) { if (vec[m] / k >= 1) { value += ((vec[m] / k) * k); } else { break; } } result[k-1] = value; } for (int i = 0; i < n; i++) { if (i > 0) { std::cout << " "; } std::cout << result[i]; } } }; int main() { Zna2024* p = new Zna2024(); p->Solve(); delete p; return 0; } |