题意,计算每颗星左下有多少颗星,不包括自己
纵坐标是非递减的,所以直接统计横坐标就行
注意树状数组不能处理x为0的时候
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=32005;
int c[maxn],ans[maxn];
int lowbit(int x)
{
return x&-x;
}
void update(int x,int add)
{
while(x<=maxn)
{
c[x]+=add;
x+=lowbit(x);
}
}
int sum(int x)
{
int ret=0;
while(x)
{
ret+=c[x];
x-=lowbit(x);
}
return ret;
}
int main()
{
int n,x,y;
while(scanf("%d",&n)!=EOF)
{
memset(c,0,sizeof(c));
memset(ans,0,sizeof(ans));
for(int i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
update(x+1,1);//x为0查询时会出现死循环,所以加一
int anss=sum(x+1);
ans[anss]++;
}
for(int i=1;i<=n;i++)
printf("%d\n",ans[i]);
}
return 0;
}