题目链接;http://acm.timus.ru/problem.aspx?space=1&num=1028
题意:给定N个点,定义一个点的level为x,y坐标都比他小的点的数量,求level为0,1……n-1的点的数量。
题解:按x坐标排序,然后对y坐标进行树状数组统计即可。需要离散化。
AC代码:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;
#define _for(i,a,b) for(int i=a;i<=b;i++)
const int maxn = 33000;
struct node
{
int x,y;
bool operator<(const node& a)const
{
if(x==a.x)return y<a.y;
return x<a.x;
}
}a[maxn];
int n,c[maxn],ans[maxn],b[maxn];
int lowbit(int x)
{
return x&-x;
}
void insert(int x)
{
while(x<=n)
{
c[x]++;
x+=lowbit(x);
}
}
int sum(int x)
{
int now = 0;
while(x>0)
{
now+=c[x];
x-=lowbit(x);
}
return now;
}
int main(int argc, char const *argv[])
{
scanf("%d",&n);
_for(i,1,n)
{
scanf("%d%d",&a[i].x,&a[i].y);
b[i]=a[i].y;
}
sort(b+1,b+1+n);
int cnt = unique(b+1,b+1+n)-b;
sort(a+1,a+1+n);
_for(i,1,n)
{
int k = lower_bound(b+1,b+1+cnt,a[i].y)-b;
int now = sum(k);
ans[now]++;
insert(k);
}
_for(i,0,n-1)printf("%d\n",ans[i]);
return 0;
}