2502021-03-06 16:39:14mraronÁdám és Éva közül legalább az egyikcpp14Accepted 40/4025ms8392 KiB
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using str = string;
 
#define xx first
#define yy second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define set_max(x,y) (x)=max((x), (y))
#define set_min(x,y) (x)=min((x), (y))
#define LOG(x) cerr<<(#x)<<" = "<<(x)<<"\n";

int d0[4][2]={{-1,0},{1,0},{0,1},{0,-1}};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int p,n,m;
	cin>>p>>n;
	vector<pair<int,int>> evs;
	for(int i=0;i<n;++i) {
		int a,b;
		cin>>a>>b;
		evs.push_back({a,1});
		evs.push_back({b,1});
	}
	cin>>m;
	for(int i=0;i<m;++i) {
		int a,b;
		cin>>a>>b;
		evs.push_back({a,2});
		evs.push_back({b,2});
	}
	
	sort(evs.begin(), evs.end());
	int st=0, prv=-1;
	vector<pair<int,int>> ans;
	for(auto i:evs) {
		if((st!=0) && prv!=i.xx) {
			if(ans.empty() || ans.back().yy!=prv) ans.eb(prv, i.xx);
			else ans.back().yy=i.xx;
		}
		st^=i.yy;
		prv=i.xx;
	}
	cout<<sz(ans)<<"\n";
	for(auto i:ans) {
		cout<<i.xx<<" "<<i.yy<<"\n";
	}
	return 0;
	
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/02ms1756 KiB
2Accepted0/01ms1880 KiB
3Accepted2/21ms1872 KiB
4Accepted2/21ms1864 KiB
5Accepted2/21ms1888 KiB
6Accepted2/21ms1872 KiB
7Accepted2/21ms1876 KiB
8Accepted2/21ms1880 KiB
9Accepted2/21ms1892 KiB
10Accepted2/21ms1888 KiB
11Accepted2/21ms1896 KiB
12Accepted2/21ms1904 KiB
13Accepted2/21ms1900 KiB
14Accepted2/21ms1900 KiB
15Accepted2/21ms1908 KiB
16Accepted2/217ms4640 KiB
17Accepted2/217ms5244 KiB
18Accepted2/214ms5752 KiB
19Accepted2/225ms6460 KiB
20Accepted2/221ms7120 KiB
21Accepted2/217ms7752 KiB
22Accepted2/217ms8392 KiB