https://loj.ac/problem/10114
Title Description
Given \ (n-\) coordinates of the points, in increasing order of y coordinate is given by the definition of a star rating on a plane horizontal and vertical coordinates are less than equal to the number of its points, each class seeking a star number.
Thinking
Because of \ (Y \) coordinates are given in increasing order, so we only need to consider \ (x \) coordinate can, since the x-coordinate range is relatively small, we directly maintain abscissa less \ (I \) point The number can have a prefix and Fenwick tree maintenance can be. However, note that arrays can not be maintained under the tree labeled \ (0 \) case, because \ (lowbit (0) = 0 \) , so be on the \ (the X-+ 1 \) .
Code
#include<bits/stdc++.h>
using namespace std;
const int N=32010;
int read()
{
int res=0,w=1;
char ch=getchar();
while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}
while(isdigit(ch))res=(res<<3)+(res<<1)+(ch^48),ch=getchar();
return res*w;
}
void write(int x)
{
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10^48);
}
void writeln(int x)
{
write(x);
putchar('\n');
}
int c[N+5],ans[N+5];
void update(int x,int v){for(;x<=N;x+=x&-x)c[x]+=v;}
int query(int x)
{
int res=0;
for(;x;x-=x&-x)res+=c[x];
return res;
}
int main()
{
int n=read();
for(int i=1;i<=n;i++)
{
int x=read()+1,y=read();
int v=query(x);
update(x,1);
ans[v]++;
}
for(int i=0;i<n;i++)
printf("%d\n",ans[i]);
}