#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(NULL); int n; std::cin >> n; std::map<int, int> m; for (int i = 1; i <= n; i++) { int x; std::cin >> x; m[x]++; } std::vector<int> res(n + 1, 0); for (auto &[key, val] : m) { for (int k = 1; k <= val; k++) res[k] += val / k; } for (int i = 1; i <= n; i++) std::cout << res[i] * i << " "; std::cout << "\n"; }
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 | #include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(NULL); int n; std::cin >> n; std::map<int, int> m; for (int i = 1; i <= n; i++) { int x; std::cin >> x; m[x]++; } std::vector<int> res(n + 1, 0); for (auto &[key, val] : m) { for (int k = 1; k <= val; k++) res[k] += val / k; } for (int i = 1; i <= n; i++) std::cout << res[i] * i << " "; std::cout << "\n"; } |