#include<iostream> #include<algorithm> #include<vector> using namespace std; int main() { ios::sync_with_stdio(0); int N,A; cin>>N; vector<int> a; for(int i=0; i<N; ++i) { cin>>A; a.push_back(A); } sort(a.begin(),a.end()); vector<int> v; for(int i=0; i<N; ++i) { int V = 1; while(i+1 < N && a[i] == a[i+1]) { i++; V++; } v.push_back(V); } int *ans = new int[N+1]; for(int i=0; i<=N; ++i) ans[i] = 0; for(int i=0; i<v.size(); ++i) { for(int j=1; j<=v[i]; ++j) { ans[j] += (v[i] / j) * j; } } for(int i=1; i<=N; ++i) cout<<ans[i]<<" "; cout<<endl; 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 | #include<iostream> #include<algorithm> #include<vector> using namespace std; int main() { ios::sync_with_stdio(0); int N,A; cin>>N; vector<int> a; for(int i=0; i<N; ++i) { cin>>A; a.push_back(A); } sort(a.begin(),a.end()); vector<int> v; for(int i=0; i<N; ++i) { int V = 1; while(i+1 < N && a[i] == a[i+1]) { i++; V++; } v.push_back(V); } int *ans = new int[N+1]; for(int i=0; i<=N; ++i) ans[i] = 0; for(int i=0; i<v.size(); ++i) { for(int j=1; j<=v[i]; ++j) { ans[j] += (v[i] / j) * j; } } for(int i=1; i<=N; ++i) cout<<ans[i]<<" "; cout<<endl; return 0; } |