Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
- //#include <ext/pb_ds/assoc_container.hpp>
- //using namespace __gnu_pbds;
- //typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
- std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
- const int INF = 1e18 + 7;
- const double EPS = 1e-10;
- const int MOD = 1e9 + 7;
- const int MAXN = 3e6 + 100;
- inline void solve() {
- int n;
- cin >> n;
- vector<int> a(n + 1);
- for (int i = 1; i <= n; ++i) {
- cin >> a[i];
- }
- map<int, int> last;
- vector<int> b;
- for (int i = 1; i <= n; ++i) {
- b.emplace_back(i - last[a[i]] - 1);
- last[a[i]] = i;
- }
- for (auto [x, y]: last) {
- b.emplace_back(n - y);
- }
- sort(b.begin(), b.end());
- vector<int> suff(b.size() + 1, 0);
- for (int i = b.size() - 1; i >= 0; --i) {
- suff[i] = suff[i + 1] + b[i];
- }
- for (int len = 1; len <= n; ++len) {
- int pos = upper_bound(b.begin(), b.end(), len - 1) - b.begin();
- cout << suff[pos] - ((int)b.size() - pos) * (len - 1) << ' ';
- }
- }
- int32_t main() {
- IOS;
- clock_t tStart = clock();
- int tt = 1;
- // cin >> tt;
- while (tt --> 0) {
- solve();
- }
- // cerr << "Runtime is:" << (long double) (clock() - tStart) / CLOCKS_PER_SEC << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment