#include <bits/stdc++.h>
using namespace std;
constexpr int maxN = 3*1e5+5;
int main()
{
int n;
vector <int> dane;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
int w;
for (int i = 0; i < n; i++)
{
cin >> w;
dane.push_back(w);
}
sort (dane.begin(), dane.end());
vector <int> ilosci;
int p = dane[0];
int l = 0;
for (int i = 0; i < n; i++)
{
if (dane[i] == p)
l++;
else
{
ilosci.push_back(l);
l = 1;
p = dane[i];
}
}
if (l)
ilosci.push_back(l);
int odpowiedzi[maxN];
bool byl[maxN];
int mnoznik[maxN];
for (int i = 0; i < ilosci.size(); i++)
mnoznik[ilosci[i]]++;
for (int i = 0; i < ilosci.size(); i++)
if (!byl[ilosci[i]])
{
for (int j = 1; j <= ilosci[i]; j++)
{
odpowiedzi[j] += mnoznik[ilosci[i]]*(ilosci[i]/j)*j;
byl[ilosci[i]] = true;
}
}
for (int i = 1; i <= n; i++)
cout << odpowiedzi[i] << " ";
exit(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 | #include <bits/stdc++.h> using namespace std; constexpr int maxN = 3*1e5+5; int main() { int n; vector <int> dane; ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; int w; for (int i = 0; i < n; i++) { cin >> w; dane.push_back(w); } sort (dane.begin(), dane.end()); vector <int> ilosci; int p = dane[0]; int l = 0; for (int i = 0; i < n; i++) { if (dane[i] == p) l++; else { ilosci.push_back(l); l = 1; p = dane[i]; } } if (l) ilosci.push_back(l); int odpowiedzi[maxN]; bool byl[maxN]; int mnoznik[maxN]; for (int i = 0; i < ilosci.size(); i++) mnoznik[ilosci[i]]++; for (int i = 0; i < ilosci.size(); i++) if (!byl[ilosci[i]]) { for (int j = 1; j <= ilosci[i]; j++) { odpowiedzi[j] += mnoznik[ilosci[i]]*(ilosci[i]/j)*j; byl[ilosci[i]] = true; } } for (int i = 1; i <= n; i++) cout << odpowiedzi[i] << " "; exit(0); } |
English