题目地址:http://poj.org/problem?id=2352
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=32000+5;
int lowbit[maxn],C[maxn];
int level[maxn];
int inline getlowbit(int i)
{return lowbit[i]?lowbit[i]:lowbit[i]=i&(-i);
}
int Sum(int p) //a[1]+a[2]+....+a[p]
{int sum=0;while(p>0){sum+=C[p];p-=getlowbit(p);}return sum;
}
void Modify(int p,int val,int n)
{while(p<=n){C[p]+=val;p+=getlowbit(p);}
}
int main()
{int n,x,y;while(cin>>n){memset(C,0,sizeof(C));memset(level,0,sizeof(level));for(int i=0;i<n;i++){scanf("%d%d",&x,&y); x++; //因为x可能等于0 level[Sum(x)]++;Modify(x,1,maxn);} for(int i=0;i<n;i++)cout<<level[i]<<endl;}return 0;
}