For example, look at the map shown on the figure above. Level of the star number 5 is equal to 3 (it's formed by three stars with a numbers 1, 2 and 4). And the levels of the stars numbered by 2 and 4 are 1. At this map there are only one star of the level 0, two stars of the level 1, one star of the level 2, and one star of the level 3.
You are to write a program that will count the amounts of the stars of each level on a given map.
#include<cstdio>
#include<cstring>
using namespace std;
int n,f[100005];
int lowbit(int x){
return x&(-x);
}
int sum(int l,int r){//求和
int ans=0;
for(int i=r;i>0;i-=lowbit(i))ans+=f[i];
for(int i=l;i>0;i-=lowbit(i))ans-=f[i];
return ans;
}
void add(int x){//进行修改操作
for(int i=x;i<=65536;i+=lowbit(i))f[i]++;
}
int x,y,vis[100005];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",&x,&y);
vis[sum(0,++x)]++;
add(x);
}
for(int i=0;i<n;i++){
printf("%d
",vis[i]);
}
}