#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
vector<int> times(n+1,0);
map<int,int> cnt;
for (int i=0; i<n; i++) {
int tmp;
cin>>tmp;
if (cnt.find(tmp)==cnt.end()) cnt[tmp]=1;
else cnt[tmp]++;
}
for (pair<int,int> it : cnt) times[it.second]++;
vector<int> res(n+1,0);
for (int i=1; i<=n; i++) {
if (!times[i]) continue;
for (int j=1; i/j>0; j++) res[j]+=times[i]*(i/j);
}
for (int i=1; i<=n; i++) cout<<res[i]*i<<' ';
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 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin>>n; vector<int> times(n+1,0); map<int,int> cnt; for (int i=0; i<n; i++) { int tmp; cin>>tmp; if (cnt.find(tmp)==cnt.end()) cnt[tmp]=1; else cnt[tmp]++; } for (pair<int,int> it : cnt) times[it.second]++; vector<int> res(n+1,0); for (int i=1; i<=n; i++) { if (!times[i]) continue; for (int j=1; i/j>0; j++) res[j]+=times[i]*(i/j); } for (int i=1; i<=n; i++) cout<<res[i]*i<<' '; return 0; } |
English