#include "bits/stdc++.h" using namespace std; int num_of_geq(const vector<int> &A, int val) { int n = A.size(); int jump = 1; while(jump*2 <= n) jump *=2; int ind = -1; while(jump) { if(ind + jump < n && A[ind + jump] >= val) ind += jump; jump/=2; } return ind+1; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; unordered_map <int, int> M; for(int i=0; i<n; i++) { int a; cin >> a; M[a]++; } vector<int> A; for(auto a : M) A.push_back(a.second); sort(A.rbegin(), A.rend()); for(int k=1; k<=n; k++){ int res=0; for(int m=k; m<=A[0]; m+=k) res+=num_of_geq(A, m) * k; cout << res << ' '; } cout << '\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 | #include "bits/stdc++.h" using namespace std; int num_of_geq(const vector<int> &A, int val) { int n = A.size(); int jump = 1; while(jump*2 <= n) jump *=2; int ind = -1; while(jump) { if(ind + jump < n && A[ind + jump] >= val) ind += jump; jump/=2; } return ind+1; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; unordered_map <int, int> M; for(int i=0; i<n; i++) { int a; cin >> a; M[a]++; } vector<int> A; for(auto a : M) A.push_back(a.second); sort(A.rbegin(), A.rend()); for(int k=1; k<=n; k++){ int res=0; for(int m=k; m<=A[0]; m+=k) res+=num_of_geq(A, m) * k; cout << res << ' '; } cout << '\n'; return 0; } |