- 题目传送门
- 题意:一个点(x , y) ,其他点(x0 , y0)中满足 x0 <= x且y0 <= y 的点的个数就是它的等级。刚开始一直不理解题意(太菜了),看了别人的博客才知道。
- 题解:题中数据读入已经按照 y依次增大的顺序读入了,所以只要将所有小于 x的点统计出来就好了,简单的树状数组求和就好了。
#include<cstdio>
#define lowbit(x) x&(-x)
#include<cstring>
using namespace std;
const int maxn = 32005,maxm = 15005;
int num[maxn],ans[maxm];
void update(int x,int d)
{
while(x < maxn)
{
num[x] += d;
x += lowbit(x);
}
}
int query(int x)
{
int res = 0;
while(x > 0)
{
res += num[x];
x -= lowbit(x);
}
return res;
}
int main()
{
int n,x,y;
while(~scanf("%d",&n)) //<=> scanf("%d",&n)!=EOF
{
memset(num,0,sizeof(num)); //不清楚为什么不清零也是对的,玄学
for(int i = 0; i < n; ++ i)
{
scanf("%d %d",&x,&y);
x++; //tle几发,因为x有可能是0,死循环(树状数组没0位)
ans[query(x)]++;
update(x,1);
}
for(int i = 0; i < n; ++ i)
{
printf("%d\n",ans[i]);
ans[i] = 0;
}
}
return 0;
}