#include <iostream> #include <algorithm> using namespace std; constexpr int maxN = 300'007; int n; int res[maxN]; int t[maxN]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { cin >> t[i]; } sort(t, t+n); for (int i = 0; i < n;) { int j = i; while (j+1 < n && t[j+1] == t[j]) { j++; } int elements = j - i + 1; for (int div = 1; div <= elements; div++) { res[div] += elements - elements % div; } i = j + 1; } for (int div = 1; div <= n; div++) { cout << res[div] << ' '; } 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 | #include <iostream> #include <algorithm> using namespace std; constexpr int maxN = 300'007; int n; int res[maxN]; int t[maxN]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { cin >> t[i]; } sort(t, t+n); for (int i = 0; i < n;) { int j = i; while (j+1 < n && t[j+1] == t[j]) { j++; } int elements = j - i + 1; for (int div = 1; div <= elements; div++) { res[div] += elements - elements % div; } i = j + 1; } for (int div = 1; div <= n; div++) { cout << res[div] << ' '; } cout << '\n'; return 0; } |