Submission #71576636


Source Code Expand

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define all(v) v.begin(), v.end()
#define memo(v, x) memset(v, x, sizeof(v))
#define sz(v) (int)v.size()


void solve() {
    int n, q;
    cin >> n >> q;
    int black = 0;
    set<pair<int, int>> v;
    auto extend = [&](int l, int r) -> void {
		auto it = v.lower_bound({l, -1});
		vector<pair<int, int>> add, remove;
		add.push_back({l, r});
		if (it != v.begin()) {
			it--;
			if ((*it).second >= l) {
				add.push_back({(*it).first, l - 1});
				if ((*it).second > r)
					add.push_back({r + 1, (*it).second});
				remove.push_back(*it);
			}
			it++;
		}
		while (it != v.end() && (*it).second <= r) {
			auto [inL, inR] = (*it);
			remove.push_back({inL, inR});
			it++;
		}
		if (it != v.end() && (*it).first <= r) {
			auto [inL, inR] = *it;
			inR = min(inR, r);
			if (r + 1 <= (*it).second)
				add.push_back({r + 1, (*it).second});
			remove.push_back(*it);
		}
		for (auto &seg : remove) {
            black -= (seg.second - seg.first + 1);
            v.erase(seg);
        }
		for (auto &seg : add) {
            black += (seg.second - seg.first + 1);
            v.insert(seg);
        }
	};
    while (q--) {
        int l, r;
        cin >> l >> r;
        extend(l, r);
        cout << n - black << '\n';
    }
}

int main() {
    cin.tie(0) -> sync_with_stdio(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        solve();
    }
    return 0;
}

Submission Info

Submission Time
Task E - Cover query
User georginio
Language C++23 (GCC 15.2.0)
Score 450
Code Size 1637 Byte
Status AC
Exec Time 187 ms
Memory 15016 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 2
AC × 42
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3532 KiB
example_01.txt AC 1 ms 3628 KiB
hand_00.txt AC 69 ms 13004 KiB
hand_01.txt AC 70 ms 12948 KiB
hand_02.txt AC 122 ms 12884 KiB
hand_03.txt AC 121 ms 13064 KiB
hand_04.txt AC 77 ms 15016 KiB
hand_05.txt AC 64 ms 14992 KiB
hand_06.txt AC 113 ms 14952 KiB
hand_07.txt AC 27 ms 3556 KiB
hand_08.txt AC 25 ms 3592 KiB
hand_09.txt AC 33 ms 3476 KiB
hand_10.txt AC 23 ms 3532 KiB
hand_11.txt AC 25 ms 3624 KiB
random_00.txt AC 102 ms 3412 KiB
random_01.txt AC 102 ms 3592 KiB
random_02.txt AC 102 ms 3592 KiB
random_03.txt AC 103 ms 3496 KiB
random_04.txt AC 102 ms 3556 KiB
random_05.txt AC 162 ms 11992 KiB
random_06.txt AC 158 ms 12080 KiB
random_07.txt AC 159 ms 11924 KiB
random_08.txt AC 160 ms 11852 KiB
random_09.txt AC 158 ms 12040 KiB
random_10.txt AC 97 ms 3596 KiB
random_11.txt AC 97 ms 3592 KiB
random_12.txt AC 97 ms 3564 KiB
random_13.txt AC 96 ms 3592 KiB
random_14.txt AC 97 ms 3628 KiB
random_15.txt AC 106 ms 3532 KiB
random_16.txt AC 107 ms 3532 KiB
random_17.txt AC 107 ms 3604 KiB
random_18.txt AC 106 ms 3752 KiB
random_19.txt AC 106 ms 3724 KiB
random_20.txt AC 184 ms 9256 KiB
random_21.txt AC 185 ms 9364 KiB
random_22.txt AC 187 ms 9476 KiB
random_23.txt AC 185 ms 9384 KiB
random_24.txt AC 185 ms 9164 KiB
random_25.txt AC 129 ms 3756 KiB
random_26.txt AC 127 ms 3760 KiB
random_27.txt AC 127 ms 3612 KiB