#include <bits/stdc++.h>
#define ft first
#define sc second
#define pb push_back
#define FOR(i,n) for(int i=0; i<n; i++)
#define FORX(i,a,b) for(int i=(a); i<=(b); i++)
#define watch(x) cerr << (#x) << " == " << (x) << endl
typedef long long ll;
typedef long double ld;
using namespace std;
const int N = 3e5;
int a[N+5], amt[N+5], cnt[N+5];
pair<int,int> sorted[777];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
FOR(i,n){
cin >> a[i];
}
sort(a, a+n);
int len = 1, j = 0;
FORX(i,1,n-1){
if (a[i-1] == a[i]) {
len++;
} else {
amt[j++] = len;
len = 1;
}
}
amt[j++] = len;
FOR(i,j){
cnt[amt[i]]++;
}
j = 0;
for (int i = n; i >= 1; i--){
if (cnt[i]){
sorted[j++] = {i, cnt[i]};
}
}
sorted[j] = {0,0};
FORX(i,1,n){
int sum = 0;
j = 0;
while (i <= sorted[j].ft){
sum += (sorted[j].ft - sorted[j].ft%i)*sorted[j].sc;
j++;
}
cout << sum << " ";
}
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 | #include <bits/stdc++.h> #define ft first #define sc second #define pb push_back #define FOR(i,n) for(int i=0; i<n; i++) #define FORX(i,a,b) for(int i=(a); i<=(b); i++) #define watch(x) cerr << (#x) << " == " << (x) << endl typedef long long ll; typedef long double ld; using namespace std; const int N = 3e5; int a[N+5], amt[N+5], cnt[N+5]; pair<int,int> sorted[777]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; FOR(i,n){ cin >> a[i]; } sort(a, a+n); int len = 1, j = 0; FORX(i,1,n-1){ if (a[i-1] == a[i]) { len++; } else { amt[j++] = len; len = 1; } } amt[j++] = len; FOR(i,j){ cnt[amt[i]]++; } j = 0; for (int i = n; i >= 1; i--){ if (cnt[i]){ sorted[j++] = {i, cnt[i]}; } } sorted[j] = {0,0}; FORX(i,1,n){ int sum = 0; j = 0; while (i <= sorted[j].ft){ sum += (sorted[j].ft - sorted[j].ft%i)*sorted[j].sc; j++; } cout << sum << " "; } return 0; } |
English