传送门
Description
Input
Output
Sample Input
5
1 1
5 1
7 1
3 3
5 5
Sample Output
1
2
1
1
0
题目大意
( n < = 15000 , 0 < = x , y < = 32000 ) (n<=15000,0<=x,y<=32000) (n<=15000,0<=x,y<=32000)
解题思路
模板树状数组
因为y是已排序的,所以只用判断x是否在左下角就OK了,那么就可以用树状数组
注意
树状数组维护中(也就是
l
o
w
b
i
t
(
)
lowbit()
lowbit())是不可以出现0的,不然会死循环
但是横坐标可能是0,所以一开始输入的时候x要+1
Code
#include <iostream>
#include <cstdio>
using namespace std;
long long n,x,y,ans[100010],c[100010];
int find (int x)//累计星星
{
long long s = 0;
for (; x > 0; x -= x & (-x))
s += c[x];
return s;
}
void add (int x)
{
for (; x <= 32001; x += x & (-x))
c[x]++;
}
int main()
{
scanf ("%lld", &n);
for (int i = 1; i <= n; i++)
{
scanf ("%lld%lld", &x, &y);
x++;
ans[find (x)]++;//累计星星级别
add (x);//加入当前星星
}
for (int i = 0; i < n; i++)
printf ("%lld\n", ans[i]);
}