#include <iostream> #include <map> #include <unordered_map> #include <vector> #include <unordered_set> #include <set> #include <queue> #include <utility> #include <algorithm> #include <cassert> #include <iomanip> #include <tuple> #include <stack> #include <deque> using namespace std; ///// TEMPLATES typedef long long ll; typedef tuple<ll, ll> ti2; typedef tuple<ll, ll, ll> ti3; typedef tuple<ll, ll, ll, ll> ti4; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<string> vs; typedef vector<ll> vi; typedef vector<ti2> vi2; typedef vector<ti3> vi3; typedef vector<vi> vvi; typedef set<ll> si; typedef set<ti2> si2; typedef set<ti3> si3; typedef multiset<ll> msi; typedef multiset<ti2> msi2; typedef multiset<ti3> msi3; typedef deque<ll> dqi; typedef deque<ti2> dqi2; typedef deque<ti3> dqi3; template<typename T> using PQS = priority_queue<T, vector<T>, greater<T> >; template<typename T> using PQG = priority_queue<T>; ///// OUT OPERATORS ostream& operator<<(ostream& os, const ti2& x) { os << "{ "; auto [a, b] = x; os << a << ", " << b; os << " }"; return os; } ostream& operator<<(ostream& os, const ti3& x) { os << "{ "; auto [a, b, c] = x; os << a << ", " << b << ", " << c; os << " }"; return os; } ostream& operator<<(ostream& os, const ti4& x) { os << "{ "; auto [a, b, c, d] = x; os << a << ", " << b << ", " << c << ", " << d; os << " }"; return os; } ostream& operator<<(ostream& os, const vi& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const vs& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const vb& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const vvb& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const vi2& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const vi3& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const vvi& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const msi& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const msi2& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const msi3& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const dqi& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const dqi2& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const dqi3& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ///// IN OPERATORS istream& operator>>(istream& is, ti2& x) { ll a, b; is >> a >> b; x = {a, b}; return is; } istream& operator>>(istream& is, ti3& x) { ll a, b, c; is >> a >> b >> c; x = {a, b, c}; return is; } istream& operator>>(istream& is, ti4& x) { ll a, b, c, d; is >> a >> b >> c >> d; x = {a, b, c, d}; return is; } int log_floor(long long x) { return 64 - __builtin_clzll(max(1LL, x)); } // PLUS ONE! int bit_cnt(ll x) { return __builtin_popcountll(x); } void rev(auto& v) { reverse(v.begin(), v.end()); } void sor(auto& v) { sort(v.begin(), v.end()); } // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣠⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣆⠀⢀⣀⣀⣤⣤⣤⣦⣦⣤⣤⣄⣀⣀⠀⢠⣾⣿⣿⣿⣿⣿⣷⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⠛⠿⣿⣿⣿⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⢿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣿⣿⡟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣿⣿⣿⣿⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⣿⠟⠀⠀⠀⠀⠀⣀⣤⣤⣤⡀⠀⠀⠀⠀⠀⢀⣤⣤⣤⣄⡀⠀⠀⠀⠀⠘⣿⡿⠿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⡟⠀⠀⠀⠀⣠⣾⣿⣿⣟⣿⡇⠀⠀⠀⠀⠀⢸⣿⣿⣻⣿⣿⣦⠀⠀⠀⠀⠸⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠁⠀⠀⠀⠀⣿⣿⣿⣿⣿⡟⢠⣶⣾⣿⣿⣷⣤⢽⣿⣿⣿⣿⣿⡇⠀⠀⣀⣤⣿⣷⣴⣶⣦⣀⡀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣤⣤⣠⣇⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⠀⠘⠻⣿⣿⣿⡿⠋⠀⢹⣿⣿⣿⣿⡇⠀⣿⣿⣿⡏⢹⣿⠉⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⢠⣾⣿⣿⣿⣿⣿⣿⣿⣶⣄⠀⠀⠹⣿⣿⠿⠋⠀⢤⣀⢀⣼⡄⠀⣠⠀⠈⠻⣿⣿⠟⠀⢸⣿⣇⣽⣿⠿⠿⠿⣿⣅⣽⣿⡇⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠁⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿⣟⠁⠀⠀⠀⠈⣿⣿⣿⡇⠀⠀⠀⠀⢀ // ⠛⠛⠛⠛⠛⠛⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛ // ⠀⠀⠀⠀⠀⠀⠘⠛⠻⢿⣿⣿⣿⣿⣿⠟⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠈⠉⠀⠀⠀⠀ [ STASZEK ] // // others/renumber vi renumber(vi& v) { if (v.empty()) return v; vi2 pairs; for (int i = 0; i < v.size(); i ++) { pairs.emplace_back(v[i], i); } sor(pairs); ll cur = 1; auto [pre_val, i] = pairs[0]; vi res(v.size()); for (auto [val, pos] : pairs) { if (pre_val != val) { cur ++; } res[pos] = cur; pre_val = val; } return res; } // inject here vi divisors(ll x) { vi v; for (ll i = 1; i * i <= x; i ++) { if (x % i == 0) { v.emplace_back(i); } if (i * i != x) { v.emplace_back(x / i); } } sor(v); return v; } void upd(int x, int cnt, vi& res) { for (int i = 1; i < res.size(); i ++) { res[i] += cnt * (x - (x % i)); } } void solve(){ ll n; cin >> n; vi v(n); for (int i = 0; i < n; i ++) cin >> v[i]; v = renumber(v); vi cnt(n + 2); for (auto e : v) cnt[e] ++; vi cnt2(n + 2); for (auto e : cnt) { cnt2[e] ++; } vi res(n + 2); for (int i = 1; i < cnt2.size(); i ++) { if (cnt2[i] == 0) continue; upd(i, cnt2[i], res); } for (int i = 1; i <= n; i ++) cout << res[i] << " "; } int main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); cout << setprecision(15) << fixed; int t = 1; // cin >> t; while (t --) solve(); 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | #include <iostream> #include <map> #include <unordered_map> #include <vector> #include <unordered_set> #include <set> #include <queue> #include <utility> #include <algorithm> #include <cassert> #include <iomanip> #include <tuple> #include <stack> #include <deque> using namespace std; ///// TEMPLATES typedef long long ll; typedef tuple<ll, ll> ti2; typedef tuple<ll, ll, ll> ti3; typedef tuple<ll, ll, ll, ll> ti4; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<string> vs; typedef vector<ll> vi; typedef vector<ti2> vi2; typedef vector<ti3> vi3; typedef vector<vi> vvi; typedef set<ll> si; typedef set<ti2> si2; typedef set<ti3> si3; typedef multiset<ll> msi; typedef multiset<ti2> msi2; typedef multiset<ti3> msi3; typedef deque<ll> dqi; typedef deque<ti2> dqi2; typedef deque<ti3> dqi3; template<typename T> using PQS = priority_queue<T, vector<T>, greater<T> >; template<typename T> using PQG = priority_queue<T>; ///// OUT OPERATORS ostream& operator<<(ostream& os, const ti2& x) { os << "{ "; auto [a, b] = x; os << a << ", " << b; os << " }"; return os; } ostream& operator<<(ostream& os, const ti3& x) { os << "{ "; auto [a, b, c] = x; os << a << ", " << b << ", " << c; os << " }"; return os; } ostream& operator<<(ostream& os, const ti4& x) { os << "{ "; auto [a, b, c, d] = x; os << a << ", " << b << ", " << c << ", " << d; os << " }"; return os; } ostream& operator<<(ostream& os, const vi& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const vs& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const vb& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const vvb& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const vi2& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const vi3& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const vvi& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const msi& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const msi2& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const msi3& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const dqi& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const dqi2& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ostream& operator<<(ostream& os, const dqi3& x) { os << "{ "; for (auto e : x) os << e << " "; os << "}"; return os; } ///// IN OPERATORS istream& operator>>(istream& is, ti2& x) { ll a, b; is >> a >> b; x = {a, b}; return is; } istream& operator>>(istream& is, ti3& x) { ll a, b, c; is >> a >> b >> c; x = {a, b, c}; return is; } istream& operator>>(istream& is, ti4& x) { ll a, b, c, d; is >> a >> b >> c >> d; x = {a, b, c, d}; return is; } int log_floor(long long x) { return 64 - __builtin_clzll(max(1LL, x)); } // PLUS ONE! int bit_cnt(ll x) { return __builtin_popcountll(x); } void rev(auto& v) { reverse(v.begin(), v.end()); } void sor(auto& v) { sort(v.begin(), v.end()); } // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣠⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣆⠀⢀⣀⣀⣤⣤⣤⣦⣦⣤⣤⣄⣀⣀⠀⢠⣾⣿⣿⣿⣿⣿⣷⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⠛⠿⣿⣿⣿⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⢿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣿⣿⡟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣿⣿⣿⣿⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⣿⠟⠀⠀⠀⠀⠀⣀⣤⣤⣤⡀⠀⠀⠀⠀⠀⢀⣤⣤⣤⣄⡀⠀⠀⠀⠀⠘⣿⡿⠿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⡟⠀⠀⠀⠀⣠⣾⣿⣿⣟⣿⡇⠀⠀⠀⠀⠀⢸⣿⣿⣻⣿⣿⣦⠀⠀⠀⠀⠸⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠁⠀⠀⠀⠀⣿⣿⣿⣿⣿⡟⢠⣶⣾⣿⣿⣷⣤⢽⣿⣿⣿⣿⣿⡇⠀⠀⣀⣤⣿⣷⣴⣶⣦⣀⡀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣤⣤⣠⣇⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⠀⠘⠻⣿⣿⣿⡿⠋⠀⢹⣿⣿⣿⣿⡇⠀⣿⣿⣿⡏⢹⣿⠉⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⢠⣾⣿⣿⣿⣿⣿⣿⣿⣶⣄⠀⠀⠹⣿⣿⠿⠋⠀⢤⣀⢀⣼⡄⠀⣠⠀⠈⠻⣿⣿⠟⠀⢸⣿⣇⣽⣿⠿⠿⠿⣿⣅⣽⣿⡇⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠁⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿⣟⠁⠀⠀⠀⠈⣿⣿⣿⡇⠀⠀⠀⠀⢀ // ⠛⠛⠛⠛⠛⠛⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛ // ⠀⠀⠀⠀⠀⠀⠘⠛⠻⢿⣿⣿⣿⣿⣿⠟⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠈⠉⠀⠀⠀⠀ [ STASZEK ] // // others/renumber vi renumber(vi& v) { if (v.empty()) return v; vi2 pairs; for (int i = 0; i < v.size(); i ++) { pairs.emplace_back(v[i], i); } sor(pairs); ll cur = 1; auto [pre_val, i] = pairs[0]; vi res(v.size()); for (auto [val, pos] : pairs) { if (pre_val != val) { cur ++; } res[pos] = cur; pre_val = val; } return res; } // inject here vi divisors(ll x) { vi v; for (ll i = 1; i * i <= x; i ++) { if (x % i == 0) { v.emplace_back(i); } if (i * i != x) { v.emplace_back(x / i); } } sor(v); return v; } void upd(int x, int cnt, vi& res) { for (int i = 1; i < res.size(); i ++) { res[i] += cnt * (x - (x % i)); } } void solve(){ ll n; cin >> n; vi v(n); for (int i = 0; i < n; i ++) cin >> v[i]; v = renumber(v); vi cnt(n + 2); for (auto e : v) cnt[e] ++; vi cnt2(n + 2); for (auto e : cnt) { cnt2[e] ++; } vi res(n + 2); for (int i = 1; i < cnt2.size(); i ++) { if (cnt2[i] == 0) continue; upd(i, cnt2[i], res); } for (int i = 1; i <= n; i ++) cout << res[i] << " "; } int main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); cout << setprecision(15) << fixed; int t = 1; // cin >> t; while (t --) solve(); return 0; } |