41292023-03-15 11:04:42horvathabelÁdám és Éva együttcpp17Runtime error 26/5032ms62900 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long; 
int main() {
	ll p,a;
	cin>>p>>a;
	vector<int> ad;
	ad.assign(p+1, 0);
	ll mx=0;
	for (int i=0; i<a;i++){
		ll x,y;
		cin>>x>>y; 
		ad[x]=1; 
		ad[y]=-1;
		mx=max(mx, y);
	} 
	ll e;
	cin>>e;
	vector<int> ev;
	ev.assign(p+1, 0);
	for (int i=0; i<e;i++){
		ll x,y;
		cin>>x>>y;
		
		ev[x]=1;
		ev[y]=-1;
		mx=max(mx,y);
	}
	vector<pair<int,int>> ans; 
	bool adi=false, evi=false;  
	for (int i=0; i<=mx;i++){
		if (ad[i]==1) adi=true;
		if (ad[i]==-1) adi=false;
		if (ev[i]==1) evi=true;
		if (ev[i]==-1) evi=false;
		
		if(adi && evi){
			int k=i,v;
			while (ev[i]!=-1 && ad[i]!=-1 && i<=mx){
				i++;
			}
			v=i;
			i--;
			ans.push_back({k,v});
		}
	}
	cout<<ans.size()<<endl;
	for (auto ins:ans) cout<<ins.first<<" "<<ins.second<<endl;
}
SubtaskSumTestVerdictTimeMemory
base26/50
1Accepted0/03ms1816 KiB
2Accepted0/04ms3352 KiB
3Accepted2/23ms2216 KiB
4Accepted2/23ms2460 KiB
5Accepted2/23ms2672 KiB
6Accepted2/23ms2856 KiB
7Accepted2/23ms3060 KiB
8Accepted2/23ms3316 KiB
9Accepted2/23ms3492 KiB
10Accepted2/23ms3736 KiB
11Accepted2/23ms3916 KiB
12Accepted2/23ms4668 KiB
13Accepted2/23ms5500 KiB
14Accepted2/23ms5588 KiB
15Accepted2/27ms11952 KiB
16Runtime error0/227ms62900 KiB
17Runtime error0/332ms62872 KiB
18Runtime error0/327ms62636 KiB
19Runtime error0/427ms62396 KiB
20Runtime error0/432ms62368 KiB
21Runtime error0/432ms62276 KiB
22Runtime error0/427ms62248 KiB