Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#pragma GCC optimize ("unroll_loops,fast_math")
- //#pragma GCC target ("avx,avx2")
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <map>
- #include <set>
- #include <unordered_map>
- #include <unordered_set>
- #include <random>
- #include <algorithm>
- #define ll long long
- #define sz(v) (int)v.size()
- #define forn(i, n) for (int i = 0; i < n; ++i)
- #define forln(i, l, n) for (int i = l; i < n; ++i)
- #define cinv(v) for (auto& x: v) cin >> x
- #define fr first
- #define se second
- #define all(v) v.begin(), v.end()
- #define pb push_back
- #define pii pair<int, int>
- #define pll pair<ld, ld>
- #define ld long double
- #define hm unordered_map
- using namespace std;
- const ll inf = (ll)2e9;
- const ll N = 5001;
- random_device rd;
- mt19937 rnd(rd());
- ll kek (vector<int>& goo, int d) {
- ll res = 0;
- ll ans = 0;
- int cnt[N];
- for (auto& x: cnt) x = 0;
- forn (i, d) {
- if (cnt[goo[i]] == 0) ++res;
- ++cnt[goo[i]];
- }
- ans += res;
- forln (i, 1, sz (goo)) {
- if (i + d - 1 >= sz (goo)) break;
- int x = goo[i - 1];
- if (cnt[x] == 1) --res;
- --cnt[x];
- if (cnt[goo[i + d - 1]] == 0) ++res;
- ++cnt[goo[i + d - 1]];
- ans += res;
- }
- return ans;
- }
- int main () {
- ios_base::sync_with_stdio (false);
- cout.tie(nullptr);
- cin.tie(nullptr);
- int n;
- cin >> n;
- vector<int> goo (n);
- cinv (goo);
- auto moo = goo;
- sort (all (moo));
- moo.resize (unique(all(moo)) - moo.begin());
- for (auto& x: goo) x = lower_bound(all (moo), x) - moo.begin();
- vector<ll> ans (n);
- forln (i, 1, n + 1) {
- ans[i - 1] = kek(goo, i);
- }
- for (auto& x: ans) cout << x << ' ';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement