214802026-01-13 10:19:08algoproÁruszállítás üres szakaszaicpp17Wrong answer 14/5096ms8240 KiB
// UUID: f03daf01-c87e-4061-9dd1-6cf7dba29627
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;


	vector<int> diffs(n+1, 0);
	for (int i=0;i<m;i++){
		int start, end;
		cin >> start >> end;
		diffs[start]++;
		diffs[end]--;
	}

	// for(int d:diffs){
	// 	cout << d << " ";
	// }
	// cout << "\n";

	if(n==1){
		cout << (diffs[1] == 0 ? 1 : 0);
		return 0;
	}

	vector<int> totals(n+1, 0);
	
	totals[1] = diffs[1];
	
	for(int i=2;i<=n;i++){
		totals[i] = totals[i-1] + diffs[i];
	}
	// for(int t:totals){
	// 	cout << t << " ";
	// }
	// cout << "\n";

	int empty_section_count = 0;

	int previous;
	int current = totals[0];
	for(int i=1;i<=n;i++){
		previous = current;
		current = totals[i];

		if(previous == 0 && current ==0){
			continue;
		}else if(previous == 0 && current != 0){
			continue;
		}else if(previous != 0 && current == 0){
			// cout << "i = " << i << ", previous = " << previous << ", current = " << current << "\n";
			empty_section_count++;
		}else{  // previous != 0 && current != 0
			continue;
		}



	}
	// cout << empty_section_count;



	// for(int i=0;i<=n;i++){
	// 	if (totals[i]==0){
	// 		empty_section_count++;
	// 		while(i<n && totals[i]==0){
	// 			i++;
	// 		}
	// 	}
	// }

	cout << (totals[1] == 0 ? empty_section_count + 1: empty_section_count);
}
SubtaskSumTestVerdictTimeMemory
base14/50
1Accepted0/01ms316 KiB
2Wrong answer0/096ms7988 KiB
3Accepted2/21ms500 KiB
4Wrong answer0/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms552 KiB
8Accepted2/21ms516 KiB
9Wrong answer0/21ms316 KiB
10Wrong answer0/21ms508 KiB
11Accepted2/21ms820 KiB
12Accepted2/22ms1076 KiB
13Wrong answer0/36ms1076 KiB
14Wrong answer0/38ms1844 KiB
15Wrong answer0/36ms1844 KiB
16Wrong answer0/367ms8164 KiB
17Wrong answer0/370ms8164 KiB
18Wrong answer0/379ms8240 KiB
19Wrong answer0/39ms3380 KiB
20Wrong answer0/314ms4148 KiB
21Wrong answer0/378ms8172 KiB
22Wrong answer0/385ms8172 KiB