标签:树状 数组 upd return using cstring turn str node
#include<cstring>
#include<cstdio>
#include<queue>
#include<iostream>
#include<algorithm>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 1e5+10;
struct node{
int x,y;
}a[N];
int n,w[N];
struct bit{
int a[N];
void update(int x,int pos){
for(int i=pos;i<=n;i+=i&(-i))
a[i] += x;
}
int sum(int pos){
int res = 0;
for(int i=pos;i;i-=i&(-i))
res += a[i];
return res;
}
int query(int l,int r){
return sum(r) - sum(l-1);
}
}bt;
int cmp(node a,node b){
return a.x < b.x;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d%d",&a[i].x,&a[i].y),w[i] = a[i].y;
sort(w+1,w+1+n);
int t = unique(w+1,w+1+n)-w-1;
for(int i=1;i<=n;++i){
a[i].y = lower_bound(w+1,w+t+1,a[i].y) - w;
}
sort(a+1,a+1+n,cmp);
int ans = 0;
for(int i=n;i>=1;--i){
int d = bt.sum(a[i].y);
if(n-i-d!=0) ans++;
bt.update(1,a[i].y);
}
printf("%d\n",ans);
return 0;
}
标签:树状 数组 upd return using cstring turn str node
原文地址:https://www.cnblogs.com/xxrlz/p/11644895.html