atabc D求条
查看原帖
atabc D求条
902351
Little_x_starTYJ楼主2024/5/25 21:47
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node {
	int l, r;
} a[500010];
bool cmp(node a, node b) {
	if (a.l != b.l)
		return a.l < b.l;
	return a.r < b.r;
}
int l[500010], r[500010];
int main() {
	ios::sync_with_stdio(false);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].l >> a[i].r;
	}
	sort(a + 1, a + 1 + n, cmp);
	for (int i = 1; i <= n; i++)
		l[i] = a[i].l, r[i] = a[i].r;
	int ans = 0;
	for (int i = 2; i <= n; i++) {
		int k = lower_bound(r + 1, r + i + 1, l[i]) - r;
		if (k > n || k == i)
			continue;
		ans += i - k;
	}
	cout << ans;
	return 0;
}
2024/5/25 21:47
加载中...