#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int liczba_rozw(int a, int e)
{
return a/e - a/(e+1);
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
int n;
cin >> n;
vector<int> v(n);
map<int, int> cntm;
for (auto &e : v)
{
cin >> e;
cntm[e]++;
}
vector<int> cnt;
cnt.reserve(cntm.size());
for (auto e : cntm)
cnt.push_back(e.second);
vector<int> ans(n+10);
for (auto &a : cnt)
{
set<int> mozliwe;
for (int i = 1; i*i <= a; i++)
{
mozliwe.insert(i);
mozliwe.insert(a/i);
}
int osoby = 1;
for (auto it = mozliwe.rbegin(); it != mozliwe.rend(); it++)
{
int e = *it;
int l = liczba_rozw(a, e);
ans[osoby] += e;
ans[osoby+l] -= e;
osoby += l;
}
}
for (int i = 1; i < n+10; i++)
ans[i] += ans[i-1];
for (int i = 1; i <= n; i++)
cout << ans[i]*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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include <bits/stdc++.h> using namespace std; typedef long long LL; int liczba_rozw(int a, int e) { return a/e - a/(e+1); } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> v(n); map<int, int> cntm; for (auto &e : v) { cin >> e; cntm[e]++; } vector<int> cnt; cnt.reserve(cntm.size()); for (auto e : cntm) cnt.push_back(e.second); vector<int> ans(n+10); for (auto &a : cnt) { set<int> mozliwe; for (int i = 1; i*i <= a; i++) { mozliwe.insert(i); mozliwe.insert(a/i); } int osoby = 1; for (auto it = mozliwe.rbegin(); it != mozliwe.rend(); it++) { int e = *it; int l = liczba_rozw(a, e); ans[osoby] += e; ans[osoby+l] -= e; osoby += l; } } for (int i = 1; i < n+10; i++) ans[i] += ans[i-1]; for (int i = 1; i <= n; i++) cout << ans[i]*i << " "; cout << "\n"; } |
English