#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
constexpr int S = 3e5 + 5;
int n, a, sup = 0, ile_grup = 0, g;
map<int, int> m;
int tab[S];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> a;
m[a]++;
}
for(auto p : m)
{
tab[ile_grup++] = p.second;
sup = max(sup, p.second);
}
sort(tab, tab + ile_grup);
g = 0;
for(int i = 1; i <= sup; i++)
{
g = lower_bound(tab + g, tab + ile_grup, i) - tab;
a = 0;
for(int j = g; j < ile_grup; j++)
{
a += (tab[j] / i) * i;
}
cout << a << ' ';
}
for(int i = sup + 1; i <= n; i++)
{
cout << 0 << ' ';
}
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 | #include <iostream> #include <algorithm> #include <map> using namespace std; constexpr int S = 3e5 + 5; int n, a, sup = 0, ile_grup = 0, g; map<int, int> m; int tab[S]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 0; i < n; i++) { cin >> a; m[a]++; } for(auto p : m) { tab[ile_grup++] = p.second; sup = max(sup, p.second); } sort(tab, tab + ile_grup); g = 0; for(int i = 1; i <= sup; i++) { g = lower_bound(tab + g, tab + ile_grup, i) - tab; a = 0; for(int j = g; j < ile_grup; j++) { a += (tab[j] / i) * i; } cout << a << ' '; } for(int i = sup + 1; i <= n; i++) { cout << 0 << ' '; } return 0; } |
English