Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- signed main() {
- // avx2 bless rng
- fastIO;
- int q, d; cin >> q >> d;
- int ans = 0;
- FOR(rq, 0, q) {
- int x; cin >> x, --x;
- if (is[x]) {
- ans -= cnt[x] * 1LL * (cnt[x] - 1) / 2;
- is[x] = 0, cnt[x] = 0;
- FOR(i, x + 1, min(MAX, x + d + 1)) {
- ans -= cnt[i] * 1LL * (cnt[i] - 1) / 2;
- --cnt[i];
- ans += cnt[i] * 1LL * (cnt[i] - 1) / 2;
- }
- }
- else {
- is[x] = 1;
- FOR(i, max(0, x - d), x) cnt[x] += is[i];
- ans += cnt[x] * 1LL * (cnt[x] - 1) / 2;
- FOR(i, x + 1, min(MAX, x + d + 1)) {
- ans -= cnt[i] * 1LL * (cnt[i] - 1) / 2;
- ++cnt[i];
- ans += cnt[i] * 1LL * (cnt[i] - 1) / 2;
- }
- }
- cout << ans << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement