题目链接
https://ac.nowcoder.com/acm/contest/16/A?
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
const int maxn = 1e5+20;
#define lowbit(x) x&(-x)
using namespace std;
int n,c[maxn],sum[maxn];
struct node{
int x;
int y;
bool operator<(const node &a){
return x < a.x;
}
}e[maxn];
void update(int x){
while(x < maxn){
sum[x]++;
x += lowbit(x);
}
}
int get_sum(int x){
int ans = 0;
while(x >= 1){
ans += sum[x];
x -= lowbit(x);
}
return ans;
}
int main(){
while(~scanf("%d",&n)){
for(int i = 1 ; i <= n ; i++){
scanf("%d%d",&e[i].x,&e[i].y);
c[i] = e[i].y;//为了离散化e[i].y
}
sort(c + 1, c + 1 + n);
int cnt = unique(c + 1 , c + 1 + n) - (c + 1);
for(int i = 1 ; i <= n ; i++){
e[i].y = lower_bound(c + 1, c + 1 + cnt,e[i].y) - c;
}
sort(e + 1, e + 1 + n);
int ans = 0;
for(int i = n ; i >= 1 ; i--){
int pp = get_sum(e[i].y);
if(n - i - pp > 0) ans++;
/*判断当前这个数,在树状数组里面找有没有比它大的,如果有的话,那么n-i-pp必大于0;设想一下,假设没有的话,那么
前面已经判断的数就会更新当前这个值的sum值。emmmmm,我表达不好,有问题请Q我:1150057360
*/
update(e[i].y);
}
printf("%d\n",ans);
}
return 0;
}