#include<cstdio> #include<vector> #include<map> using namespace std; int main() { int n; scanf("%d", &n); map<int, int> counts; vector<int> res(n + 8, 0); for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); if (counts.find(x) == counts.end()) { counts[x] = 1; } else { counts[x]++; } } for (map<int, int>::iterator it = counts.begin(); it != counts.end(); it++) { for (int j = 1; j <= it->second; ++j) { res[j] += it->second - it->second % j; } } for (int i = 1; i <= n; ++i) { printf("%d ", res[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 | #include<cstdio> #include<vector> #include<map> using namespace std; int main() { int n; scanf("%d", &n); map<int, int> counts; vector<int> res(n + 8, 0); for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); if (counts.find(x) == counts.end()) { counts[x] = 1; } else { counts[x]++; } } for (map<int, int>::iterator it = counts.begin(); it != counts.end(); it++) { for (int j = 1; j <= it->second; ++j) { res[j] += it->second - it->second % j; } } for (int i = 1; i <= n; ++i) { printf("%d ", res[i]); } printf("\n"); return 0; } |