题意:求
思路:很老的题目,一维排序,二维BIT,离散搞一下。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
int n;
struct unt{
int m,s;
}bk[maxn];
bool cmp(unt a,unt b){
return a.m < b.m;
}
vector<int> v;
int getid(int x){return lower_bound(v.begin(),v.end(),x)-v.begin()+1;}
int c[maxn];
int lowbit(int x){return x&-x;}
void add(int i){
for(;i<maxn;i+=lowbit(i)) c[i]++;
}
int query(int i){
int res = 0;
for(;i>0;i-=lowbit(i)){
res += c[i];
}
return res;
}
void work(){
sort(bk,bk+n,cmp);
int ans = 0,p,last = 0,sz = v.size();
for(int i=n-1;i>=0;i--){
p = getid(bk[i].s);
if(query(sz)-query(p)) ans++;
add(p);
}
printf("%d\n",ans);
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d%d",&bk[i].m,&bk[i].s);
v.push_back(bk[i].s);
}
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
work();
return 0;
}