Submission #71489617


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define debug(arg) cout << "[" << #arg << "]: " << arg << endl
#else
#define debug(arg) 42
#endif

using llu = uint64_t;
using ll = int64_t;

#define vec vector
#define pb push_back
#define all(n) begin(n), end(n)

void solv() {
	int n, q; cin >> n >> q;
	map<int, int> ranges;
	int ans = 0;
	while (q--) {
		int l, r; cin >> l >> r;
		auto it = ranges.lower_bound(l);
		while (it != ranges.end() && it->first <= r) {
			r = max(r, it->second);
			ans -= it->second - it->first + 1;
			it = ranges.erase(it);
		}
		if (it != ranges.begin()) {
			--it;
			if (it->second >= l) {
				l = min(l, it->first);
				r = max(r, it->second);
				ans -= it->second - it->first + 1;
				it = ranges.erase(it);
			}
		}
		ranges[l] = r;
		ans += r - l + 1;
		cout << n - ans << '\n';
	}
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int t = 1;
	//cin >> t;
	while (t--) solv();
	return 0;
}

Submission Info

Submission Time
Task E - Cover query
User fisher199
Language C++23 (Clang 21.1.0)
Score 450
Code Size 1008 Byte
Status AC
Exec Time 222 ms
Memory 12360 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 8 ms 3000 KiB
example_01.txt AC 1 ms 2880 KiB
hand_00.txt AC 215 ms 12360 KiB
hand_01.txt AC 215 ms 12272 KiB
hand_02.txt AC 162 ms 3016 KiB
hand_03.txt AC 163 ms 2876 KiB
hand_04.txt AC 215 ms 12280 KiB
hand_05.txt AC 187 ms 12340 KiB
hand_06.txt AC 192 ms 7708 KiB
hand_07.txt AC 128 ms 2904 KiB
hand_08.txt AC 78 ms 2984 KiB
hand_09.txt AC 173 ms 2876 KiB
hand_10.txt AC 77 ms 2880 KiB
hand_11.txt AC 77 ms 3024 KiB
random_00.txt AC 162 ms 2904 KiB
random_01.txt AC 163 ms 2928 KiB
random_02.txt AC 162 ms 2876 KiB
random_03.txt AC 163 ms 2936 KiB
random_04.txt AC 162 ms 2916 KiB
random_05.txt AC 221 ms 6316 KiB
random_06.txt AC 222 ms 6356 KiB
random_07.txt AC 221 ms 6328 KiB
random_08.txt AC 222 ms 6392 KiB
random_09.txt AC 221 ms 6360 KiB
random_10.txt AC 162 ms 2984 KiB
random_11.txt AC 162 ms 2928 KiB
random_12.txt AC 162 ms 2984 KiB
random_13.txt AC 162 ms 3016 KiB
random_14.txt AC 162 ms 2972 KiB
random_15.txt AC 163 ms 2772 KiB
random_16.txt AC 163 ms 2900 KiB
random_17.txt AC 163 ms 2984 KiB
random_18.txt AC 163 ms 2904 KiB
random_19.txt AC 163 ms 2892 KiB
random_20.txt AC 202 ms 4264 KiB
random_21.txt AC 203 ms 4296 KiB
random_22.txt AC 203 ms 4288 KiB
random_23.txt AC 203 ms 4140 KiB
random_24.txt AC 202 ms 4156 KiB
random_25.txt AC 163 ms 2772 KiB
random_26.txt AC 162 ms 3024 KiB
random_27.txt AC 163 ms 2936 KiB