41302023-03-15 11:06:04horvathabelÁdám és Éva együttcpp17Runtime error 26/5032ms63480 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<ll, ll>> ans; 
	bool adi=false, evi=false;  
	for (ll 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/03ms1812 KiB
2Accepted0/04ms3408 KiB
3Accepted2/23ms2220 KiB
4Accepted2/23ms2364 KiB
5Accepted2/23ms2532 KiB
6Accepted2/23ms2744 KiB
7Accepted2/23ms2820 KiB
8Accepted2/23ms2976 KiB
9Accepted2/23ms2932 KiB
10Accepted2/23ms2948 KiB
11Accepted2/23ms2912 KiB
12Accepted2/23ms3524 KiB
13Accepted2/23ms4300 KiB
14Accepted2/24ms4388 KiB
15Accepted2/26ms10884 KiB
16Runtime error0/228ms63480 KiB
17Runtime error0/329ms63460 KiB
18Runtime error0/330ms63428 KiB
19Runtime error0/428ms63400 KiB
20Runtime error0/429ms63392 KiB
21Runtime error0/432ms63152 KiB
22Runtime error0/430ms63120 KiB