#include <bits/stdc++.h> using namespace std; #define st first #define nd second #define ll long long const ll maxn = 3e5 + 7; ll n, licz, t[maxn], res[maxn]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> t[i]; } sort(t + 1, t + n + 1); for(int i = 1; i <= n + 1; i++){ if(t[i] != t[i - 1]){ for(int j = 1; j <= licz; j++) res[j] += (licz / j) * j; licz = 0; } licz++; } for(int i = 1; i <= n; i++) cout << res[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 24 25 26 27 28 29 30 31 32 | #include <bits/stdc++.h> using namespace std; #define st first #define nd second #define ll long long const ll maxn = 3e5 + 7; ll n, licz, t[maxn], res[maxn]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> t[i]; } sort(t + 1, t + n + 1); for(int i = 1; i <= n + 1; i++){ if(t[i] != t[i - 1]){ for(int j = 1; j <= licz; j++) res[j] += (licz / j) * j; licz = 0; } licz++; } for(int i = 1; i <= n; i++) cout << res[i] << " "; cout << '\n'; } |