#include <iostream> #include <algorithm> #include <vector> using namespace std; #define MAXN 300001 int answer[MAXN]; int main() { ios::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); int n; cin >> n; int arr[n]; for(int& i : arr) cin >> i; sort(arr, arr+n); vector<int> vec = {1}; for(int i = 1; i < n; ++i) { if(arr[i] > arr[i-1]) vec.push_back(1); else vec.back()++; } for(const int& i : vec) for(int j = 1; j <= i; ++j) answer[j] += (i/j)*j; for(int i = 1; i <= n; ++i) cout << answer[i] << ' '; }
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 | #include <iostream> #include <algorithm> #include <vector> using namespace std; #define MAXN 300001 int answer[MAXN]; int main() { ios::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); int n; cin >> n; int arr[n]; for(int& i : arr) cin >> i; sort(arr, arr+n); vector<int> vec = {1}; for(int i = 1; i < n; ++i) { if(arr[i] > arr[i-1]) vec.push_back(1); else vec.back()++; } for(const int& i : vec) for(int j = 1; j <= i; ++j) answer[j] += (i/j)*j; for(int i = 1; i <= n; ++i) cout << answer[i] << ' '; } |