(1)贪心
题目链接https://blog.csdn.net/ayf1988/article/details/101418391
啊啊啊啊正解写挂,真的是练题不够吧
就是按x从小到大排序,遇到一个点如果是入口就二分查找最小值取出,是出口就加入;
set维护
#include <set>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=1e6+10;
inline int read() {
int x=0;char ch=getchar();
while(!isdigit(ch)) ch=getchar();
while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
return x;
}
int n,t,ans,x,y;
int pos[N];
bool num[N];
set<int>s;
int main() {
t=read();
n=read();
for(int i=1;i<=n;i++) {
x=read();y=read();
num[x]=1;
pos[x]=y;
}
for(int i=1;i<=n;i++) {
x=read();y=read();
num[x]=0;
pos[x]=y;
}
for(int i=0;i<2*n;i++) {
if(num[i]) s.insert(pos[i]);
else {
set<int>::iterator p=s.lower_bound(pos[i]);
if(p==s.begin()) continue;
p--;
ans++;
s.erase(p);
}
}
printf("%d
",ans);
return 0;
}