http://poj.org/problem?id=2352
#include <stdio.h> #define Max 17000 #define Maxn 320005 #define Lowbit(x) x&(-x) #define Rep(i,n) for(i = 0;i < n;i ++) int c[Maxn],r[Max]; void update(int n) { while(n < 320005) { c[n] ++; n += Lowbit(n); } } int getSum(int n) { int sum = 0; while(n > 0) { sum += c[n]; n -= Lowbit(n); } return sum; } int main() { int n,i,x,y; scanf("%d",&n); Rep(i,n) { scanf("%d %d",&x,&y); r[getSum(x+1)]++; update(x+1); } Rep(i,n) printf("%d\n",r[i]); return 0; }