MnZn刚学oi,求调
查看原帖
MnZn刚学oi,求调
448018
KAqwq楼主2024/7/19 20:40
#include <bits/stdc++.h>
#define N 500005
#define pll std::pair <LL, LL>
#define mp std::make_pair
#define fi first
#define se second

typedef long long LL;
LL n;
struct node {
	LL a, b;
	friend bool operator <(node x, node y) {
		return x.a < y.a;
	}
}a[2][N];
LL m[2];
std::priority_queue <LL, std::vector <LL>, std::greater <LL> >q1;
std::priority_queue <pll, std::vector <pll>, std::greater <pll> >q2;
LL ans[2][N], cnt, t[N];
int main() {
	std::cin >> n >> m[0] >> m[1];
	for (LL k = 0; k < 2; ++k) {
		for (LL i = 1; i <= m[k]; ++i) std::cin >> a[k][i].a >> a[k][i].b;
		std::sort (a[k] + 1, a[k] + 1 + m[k]);
	}
	for (LL k = 0; k < 2; ++k) {
		memset (t, 0, sizeof(t)); cnt = 0;
		while (!q1.empty()) q1.pop(); while (!q2.empty()) q2.pop();	
		for (LL i = 1; i <= m[k]; ++i) {
			while (!q2.empty() && q2.top().fi <= a[k][i].a) {
				q1.push (q2.top().se); q2.pop();
			}
			if (!q1.empty()) {
				q2.push (mp(a[k][i].b, q1.top())); q1.pop();
			} else {
				q2.push (mp(a[k][i].b, ++cnt));
			}
			++ans[k][cnt];
		}
		for (LL i = 1; i <= n; ++i) {
			ans[k][i] += ans[k][i - 1];
		} 
	}
	LL maxn = INT_MIN;
	for (LL i = 0; i <= n; ++i) maxn = std::max (maxn, ans[0][i] + ans[0][n - i]);
	std::cout << maxn;
	return 0;
}
2024/7/19 20:40
加载中...