#include <cstdio> #include <map> #define REP(a, n) for (int a = 0; a < (n); ++a) #define FOR(a, b, c) for (int a = (b); a <= (c); ++a) using namespace std; ////////////////////// int N; int wyn[300005]; map<int,int> M; int main() { scanf("%d", &N); REP(a, N) { int b; scanf("%d", &b); M[b]++; } for (auto p : M) { int w = p.second; FOR(k, 1, w) wyn[k] += w/k*k; } FOR(k, 1, N) printf("%d%c", wyn[k], k==N?'\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 | #include <cstdio> #include <map> #define REP(a, n) for (int a = 0; a < (n); ++a) #define FOR(a, b, c) for (int a = (b); a <= (c); ++a) using namespace std; ////////////////////// int N; int wyn[300005]; map<int,int> M; int main() { scanf("%d", &N); REP(a, N) { int b; scanf("%d", &b); M[b]++; } for (auto p : M) { int w = p.second; FOR(k, 1, w) wyn[k] += w/k*k; } FOR(k, 1, N) printf("%d%c", wyn[k], k==N?'\n':' '); } |