2282021-03-05 10:49:36mraronÁdám és Éva együttcpp14Accepted 50/5020ms8392 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==3) && 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
base50/50
1Accepted0/02ms1756 KiB
2Accepted0/02ms1816 KiB
3Accepted2/21ms1856 KiB
4Accepted2/21ms1860 KiB
5Accepted2/21ms1860 KiB
6Accepted2/21ms1868 KiB
7Accepted2/21ms1876 KiB
8Accepted2/21ms1880 KiB
9Accepted2/21ms1876 KiB
10Accepted2/21ms1884 KiB
11Accepted2/21ms1892 KiB
12Accepted2/21ms1900 KiB
13Accepted2/21ms1900 KiB
14Accepted2/21ms1900 KiB
15Accepted2/21ms1900 KiB
16Accepted2/220ms4600 KiB
17Accepted3/320ms5244 KiB
18Accepted3/318ms5752 KiB
19Accepted4/419ms6460 KiB
20Accepted4/418ms7068 KiB
21Accepted4/417ms7756 KiB
22Accepted4/417ms8392 KiB