此题主要用到排序,贪心,multiset容器
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
int n;
struct node{
ll x,y,z;
bool operator<(const node a){
if(x!=a.x)return x<a.x;
if(y!=a.y)return y<a.y;
}
}dot[100010];
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%lld %lld %lld",&dot[i].x,&dot[i].y,&dot[i].z);
}
sort(dot,dot+n);
multiset<ll> p;//set的延伸,复杂度为log(n),代替vector
//p中储存的是z值为0的点
multiset<ll>::iterator it;
ll ans=0;
for(int i=0;i<n;i++){
if(dot[i].z){
it=p.lower_bound(dot[i].y);//找到第一个大于等于dot[i].y的点
if(it!=p.begin()){
it--;//找到最大的"小于"dot[i]的点(最优方案)
p.erase(it);//消除此点
ans++;
}
}
else {
p.insert(dot[i].y);
}
}
cout<<ans<<endl;
return 0;
}
// /\ | / |**、
// / \ | / | \
// / \ |/ | / _____ ____ | /
// /------\ |\ |__/ / \ \ /\ / / \ | /
// / \ | \ | / \ \ / \ / /______\ |/
// / \ | \ | \ / \ / \ / \ |
// / \ | \ | \_____/ \/ \/ \_____ |
/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
// warm heart, wagging tail,and a smile just for you!
//
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// .' \| |// `.
// / \||| : |||// \
// / _||||| -:- |||||- \
// | | \\ - /// | |
// | \_| ''\---/'' | |
// \ .-\__ `-` ___/-. /
// ___`. .' /--.--\ `. . __
// ."" '< `.___\_<|>_/___.' >'"".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `-. \_ __\ /__ _/ .-` / /
// ======`-.____`-.___\_____/___.-`____.-'======
// `=---='
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//