#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 300005;
int n, a, leftIdx;
unordered_map<int, int> citiesCounts, amountsCounts;
vector<pair<int, int>> amountsWithCounts;
int solve(const int k)
{
if(leftIdx >= amountsWithCounts.size())
{
return 0;
}
int res = 0;
for(int i = leftIdx; i < amountsWithCounts.size(); ++i)
{
const auto& curr = amountsWithCounts[i];
if(curr.first < k)
{
leftIdx = i+1;
continue;
}
res += (curr.first/k) * curr.second * k;
}
return res;
}
int main()
{
ios::sync_with_stdio(0);
cin >> n;
for(int i = 0; i < n; ++i)
{
cin >> a;
++citiesCounts[a];
}
for(const auto& entry : citiesCounts)
{
++amountsCounts[entry.second];
}
for(const auto& entry : amountsCounts)
{
//cout << entry.first << " -> " << entry.second << endl;
amountsWithCounts.push_back(entry);
}
sort(amountsWithCounts.begin(), amountsWithCounts.end());
for(int i = 1; i <= n; ++i)
{
int res = solve(i);
cout << res << ' ';
}
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #include <bits/stdc++.h> using namespace std; const int MAX_N = 300005; int n, a, leftIdx; unordered_map<int, int> citiesCounts, amountsCounts; vector<pair<int, int>> amountsWithCounts; int solve(const int k) { if(leftIdx >= amountsWithCounts.size()) { return 0; } int res = 0; for(int i = leftIdx; i < amountsWithCounts.size(); ++i) { const auto& curr = amountsWithCounts[i]; if(curr.first < k) { leftIdx = i+1; continue; } res += (curr.first/k) * curr.second * k; } return res; } int main() { ios::sync_with_stdio(0); cin >> n; for(int i = 0; i < n; ++i) { cin >> a; ++citiesCounts[a]; } for(const auto& entry : citiesCounts) { ++amountsCounts[entry.second]; } for(const auto& entry : amountsCounts) { //cout << entry.first << " -> " << entry.second << endl; amountsWithCounts.push_back(entry); } sort(amountsWithCounts.begin(), amountsWithCounts.end()); for(int i = 1; i <= n; ++i) { int res = solve(i); cout << res << ' '; } return 0; } |
English