#include <iostream> #include <vector> #include <unordered_map> using namespace std; unordered_map<int, int> M; vector <int> V; int T[300'002]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; i ++) { int a; cin >> a; M[a] ++; } for (auto i : M) V.push_back(i.second); for (auto i : V) { for (int j = 1; i / j > 0; j++) T[j] += (i / j) * j; } for (int i = 1; i <= n; i++) cout << T[i] << ' '; 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 | #include <iostream> #include <vector> #include <unordered_map> using namespace std; unordered_map<int, int> M; vector <int> V; int T[300'002]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; i ++) { int a; cin >> a; M[a] ++; } for (auto i : M) V.push_back(i.second); for (auto i : V) { for (int j = 1; i / j > 0; j++) T[j] += (i / j) * j; } for (int i = 1; i <= n; i++) cout << T[i] << ' '; cout << '\n'; } |