题目链接
树状数组入门
#include<cstdio>
#include<cstring>
const int N=4e4;
int sum[N],a[N],n;
int lowbit(int x)
{
return x&(-x);
}
int query(int x)
{
int ans=0;
while(x>0)
{
ans+=a[x];
x-=lowbit(x);
}
return ans;
}
void update(int x,int v)
{
while(x<=N)
{
a[x]+=v;
x+=lowbit(x);
}
}
int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d",&n))
{
memset(a,0,sizeof(a));
memset(sum,0,sizeof(sum));
int i,x,y;
for(i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
update(x+1,1);
sum[query(x+1)-1]++;
}
for(i=0;i<n;i++)
printf("%d\n",sum[i]);
}
return 0;
}