#include <bits/stdc++.h> #pragma GCC optimize("O2") //#pragma GCC optimize ("trapv") using namespace std; #ifdef local #include "debug.h" #define pr(...) debug(#__VA_ARGS__, __VA_ARGS__) #define prs(...) debug_nameless(__VA_ARGS__) #else #define pr(...) 69 #define prs(...) 69 #endif #define pb push_back #define endl '\n' typedef double dbl; typedef long long ll; typedef unsigned long long ull; const int inf = 1e9; const ll binf = 1e18; const dbl eps = 1e-9; void setIO(string s = "") { ios_base::sync_with_stdio(0); cin.tie(0); if(s.size() > 0){ freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } } void solve(int tc){ int n; cin >> n; vector <int> arr(n); for(int i = 0; i < n; i++){ cin >> arr[i]; } map <int, int> map; //quantas vezes cada selo aparece for(int i = 0; i < n; i++){ map[arr[i]] += 1; } //freq[i] -> quantos selos aparecem i vezes vector <int> freq(n+1); for(auto tmp : map){ freq[tmp.second] += 1; } vector <pair<int,int>> new_arr; //new array -> frequencia de cada valor nao 0 for(int i = 1; i <= n; i++){ if(freq[i] != 0){ new_arr.pb({freq[i], i}); } } int k = new_arr.size(); vector <int> ans(n); for(int i = 1; i <= n; i++){ int curr = 0; for(int j = 0; j < k; j++){ curr += (new_arr[j].second - (new_arr[j].second % i))*new_arr[j].first; } ans[i-1] = curr; } for(int x : ans){ cout << x << " "; } cout << endl; } int main(){ setIO(); int tc = -1; tc = 1; if(tc != 1) cin >> tc; for (int t = 0; t < tc; t++) { pr(t); prs(string(50, '-')); solve(t); prs(string(50, '-') + "\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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | #include <bits/stdc++.h> #pragma GCC optimize("O2") //#pragma GCC optimize ("trapv") using namespace std; #ifdef local #include "debug.h" #define pr(...) debug(#__VA_ARGS__, __VA_ARGS__) #define prs(...) debug_nameless(__VA_ARGS__) #else #define pr(...) 69 #define prs(...) 69 #endif #define pb push_back #define endl '\n' typedef double dbl; typedef long long ll; typedef unsigned long long ull; const int inf = 1e9; const ll binf = 1e18; const dbl eps = 1e-9; void setIO(string s = "") { ios_base::sync_with_stdio(0); cin.tie(0); if(s.size() > 0){ freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } } void solve(int tc){ int n; cin >> n; vector <int> arr(n); for(int i = 0; i < n; i++){ cin >> arr[i]; } map <int, int> map; //quantas vezes cada selo aparece for(int i = 0; i < n; i++){ map[arr[i]] += 1; } //freq[i] -> quantos selos aparecem i vezes vector <int> freq(n+1); for(auto tmp : map){ freq[tmp.second] += 1; } vector <pair<int,int>> new_arr; //new array -> frequencia de cada valor nao 0 for(int i = 1; i <= n; i++){ if(freq[i] != 0){ new_arr.pb({freq[i], i}); } } int k = new_arr.size(); vector <int> ans(n); for(int i = 1; i <= n; i++){ int curr = 0; for(int j = 0; j < k; j++){ curr += (new_arr[j].second - (new_arr[j].second % i))*new_arr[j].first; } ans[i-1] = curr; } for(int x : ans){ cout << x << " "; } cout << endl; } int main(){ setIO(); int tc = -1; tc = 1; if(tc != 1) cin >> tc; for (int t = 0; t < tc; t++) { pr(t); prs(string(50, '-')); solve(t); prs(string(50, '-') + "\n"); } return 0; } |