题意:
给定 个整数对
,问存在多少个
满足 :
,其中
。
题解:
先对数对按 排序,那么对于
,会有
。
因此,对于,我们只需要考虑是否存在
。
这样我们逆序遍历,维护一个后缀最大的 值,即可判断
是否满足条件。
Code:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct Node {
int a, b;
Node() { }
bool operator < (const Node &t) const {
return a < t.a;
}
}p[N];
int n;
int main() {
cin >> n;
for(int i = 1; i <= n; i++) cin >> p[i].a >> p[i].b;
sort(p + 1, p + n + 1);
int ans = 0;
int mx = 0;
for(int i = n; i >= 1; i--) {
if(p[i].b <= mx) ans++;
mx = max(p[i].b, mx);
}
cout << ans << endl;
return 0;
} 
京公网安备 11010502036488号