离散化+区间覆盖
但是区间覆盖可以使用并查集优化
没什么难度,直接上代码:
#include<bits/stdc++.h>
#define LL long long
using namespace std;
struct hh{LL x,l,r;}a[1000010];
LL n,x,y,z,ans;
LL b[2000010];
int f[2000010];
bool v[2000010];
bool cmp(hh h1,hh h2){
return h1.x<h2.x;
}
int find(int x){
if(f[x]==x) return x;
return f[x]=find(f[x]);
}
int main(){
cin>>n;
for(int i=1;i<=n;++i){
scanf("%lld%lld%lld",&x,&y,&z);
a[i]=(hh){y,(-x-1)*z,-x*z};
b[i*2-1]=(-x-1)*z,b[i*2]=-x*z;
}
sort(a+1,a+n+1,cmp);
sort(b+1,b+n*2+1);
int bt=unique(b+1,b+n*2+1)-b;
for(int i=1;i<=n;++i){
a[i].l=lower_bound(b+1,b+bt+1,a[i].l)-b;
a[i].r=lower_bound(b+1,b+bt+1,a[i].r)-b-1;
}
for(int i=1;i<=bt+5;++i) f[i]=i;
for(int i=1;i<=n;++i)
for(int j=find(a[i].l);j<=a[i].r;j=find(j))
v[i]=1,f[j]=j+1;
for(int i=1;i<=n;++i) ans+=v[i];
cout<<ans;
return 0;
}
有关这类用并查集优化填充的内容,可以去看 https://wikioi.cn/article/36347 的第五章
并查集是个好东西,一定要充分利用