138142025-01-08 19:59:54mateÁruszállítás üres szakaszaicpp17Accepted 50/50101ms2564 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,m; cin >> n >> m;
	vector <pair <int,int>> v;
	for(int i = 0; i < m; i++){
		int a,b; cin >> a >> b;
		v.push_back({a,1});
		v.push_back({b,2});
	}
	sort(v.begin(),v.end());
	/*for(auto x : v){
		cout << x.first << ' ' << x.second << '\n';
	}*/
	//vector <int> szumma(n+1,0);
	int cnt = 0;
	int ans = 0;
	bool ansp = 0;
	int j = 0;
	bool bent = 1;
	for(int i = 1; i <= n; i++){
		if(ansp){
			ans++;
			ansp = 0;
			bent = 0;
		}
		while(i == v[j].first){
			if(v[j].second == 1){
				cnt++;
			}
			if(v[j].second == 2){
				cnt--;
			}
			
			j++;
			bent = 1;
		}
		if(cnt == 0 && bent){
			//ans++;
			ansp = 1;
		}else{
			//ansp = 0;
		}
		
	}
	cout << ans;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/0101ms2504 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms508 KiB
10Accepted2/21ms316 KiB
11Accepted2/21ms508 KiB
12Accepted2/22ms416 KiB
13Accepted3/36ms564 KiB
14Accepted3/38ms564 KiB
15Accepted3/36ms568 KiB
16Accepted3/374ms2564 KiB
17Accepted3/376ms2512 KiB
18Accepted3/386ms2480 KiB
19Accepted3/39ms764 KiB
20Accepted3/310ms564 KiB
21Accepted3/392ms2476 KiB
22Accepted3/396ms2544 KiB