156062025-02-21 09:09:14GervidÁdám és Éva együttcpp17Elfogadva 50/5025ms2124 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits.h>
#include <algorithm>
#include <math.h>
#include <array>

using namespace std;

int main()
{
	iostream::sync_with_stdio(0);
	cin.tie(0);

	int n, a, e, i;
	cin >> n >> a;

	vector<array<int, 2>> va(a);
	vector<int> points;
	points.reserve(2e5);
	for (i = 0; i < a; i++)
	{
		cin >> va[i][0] >> va[i][1];
		points.push_back(va[i][0]);
		points.push_back(va[i][1]);
	}

	cin >> e;
	vector<array<int, 2>> ve(e);
	for (i = 0; i < e; i++)
	{
		cin >> ve[i][0] >> ve[i][1];
		points.push_back(ve[i][0]);
		points.push_back(ve[i][1]);
	}

	sort(points.begin(), points.end());
	points.erase(unique(points.begin(), points.end()), points.end());

	vector<int> d(points.size(), 0);
	for (i = 0; i < a; i++)
	{
		d[lower_bound(points.begin(), points.end(), va[i][0]) - points.begin()]++;
		d[lower_bound(points.begin(), points.end(), va[i][1]) - points.begin()]--;
	}
	for (i = 0; i < e; i++)
	{
		d[lower_bound(points.begin(), points.end(), ve[i][0]) - points.begin()]++;
		d[lower_bound(points.begin(), points.end(), ve[i][1]) - points.begin()]--;
	}

	vector<int> overlap(points.size(), 0);
	int diff = 0;
	for (i = 0; i < overlap.size(); i++)
	{
		diff += d[i];
		overlap[i] = diff;
	}

	vector<array<int, 2>> ans;
	ans.reserve(a);
	for (i = 0; i < overlap.size(); i++)
	{
		if (overlap[i] == 2)
		{
			ans.push_back({ points[i], points[i + 1] });
		}
	}
	cout << ans.size() << '\n';
	for (i = 0; i < ans.size(); i++)
	{
		cout << ans[i][0] << ' ' << ans[i][1] << '\n';
	}
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/01ms316 KiB
2Elfogadva0/01ms316 KiB
3Elfogadva2/21ms316 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/21ms316 KiB
6Elfogadva2/21ms344 KiB
7Elfogadva2/21ms316 KiB
8Elfogadva2/21ms316 KiB
9Elfogadva2/21ms316 KiB
10Elfogadva2/21ms316 KiB
11Elfogadva2/21ms508 KiB
12Elfogadva2/21ms316 KiB
13Elfogadva2/21ms316 KiB
14Elfogadva2/21ms316 KiB
15Elfogadva2/21ms344 KiB
16Elfogadva2/224ms2012 KiB
17Elfogadva3/324ms1900 KiB
18Elfogadva3/320ms1732 KiB
19Elfogadva4/421ms1848 KiB
20Elfogadva4/425ms2124 KiB
21Elfogadva4/423ms1948 KiB
22Elfogadva4/424ms2040 KiB