#include <stdio.h> #include <stdlib.h> #define NN 300001 int cmpfunc (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } int mm[NN], ll[NN], ww[NN]; int debug = 0; int main() { int i, j, k, l, m, n; scanf("%d", &n); for (i=0; i<n; i++) scanf("%d", &mm[i]); qsort(mm, n, sizeof(int), cmpfunc); mm[n] = -1; if (debug != 0) { for (i=0; i<=n; i++) printf("%d ", mm[i]); printf("\n"); } l = 0; m = 0; k = mm[0]; for (i=0; i<=n; i++) if (mm[i]==k) l++; else { ll[l]++; k = mm[i]; if (l > m) m = l; l = 1; } if (debug != 0) { for (i=0; i<=m; i++) printf("%d ", ll[i]); printf("\n"); } for (i=0; i<=m; i++) if (ll[i] != 0) { l = ll[i]; for (j=1; j<=i; j++) ww[j] += l * (i / j); } for (i=1; i<=n; i++) printf("%d ", ww[i]*i); printf("\n"); 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 67 68 69 70 | #include <stdio.h> #include <stdlib.h> #define NN 300001 int cmpfunc (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } int mm[NN], ll[NN], ww[NN]; int debug = 0; int main() { int i, j, k, l, m, n; scanf("%d", &n); for (i=0; i<n; i++) scanf("%d", &mm[i]); qsort(mm, n, sizeof(int), cmpfunc); mm[n] = -1; if (debug != 0) { for (i=0; i<=n; i++) printf("%d ", mm[i]); printf("\n"); } l = 0; m = 0; k = mm[0]; for (i=0; i<=n; i++) if (mm[i]==k) l++; else { ll[l]++; k = mm[i]; if (l > m) m = l; l = 1; } if (debug != 0) { for (i=0; i<=m; i++) printf("%d ", ll[i]); printf("\n"); } for (i=0; i<=m; i++) if (ll[i] != 0) { l = ll[i]; for (j=1; j<=i; j++) ww[j] += l * (i / j); } for (i=1; i<=n; i++) printf("%d ", ww[i]*i); printf("\n"); return 0; } |