POJ 2352
#include<iostream> #define MAXN 35000 using namespace std; int ans[MAXN]; int c[MAXN]; int plus(int place,int value); int give_end(int end); int main() { //freopen("acm.acm","r",stdin); int num; int u; int v; int i; memset(c,0,sizeof(c)); memset(ans,0,sizeof(ans)); cin>>num; int temp = num; while(num --) { cin>>u>>v; ans[give_end(u+1)] += 1; plus(u+1,1); } for(i = 0; i < temp; ++ i) { cout<<ans[i]<<endl; } return 0; } int lowbit(int t) { return t&(t^(t-1)); } int give_end(int end) { int sum = 0; while(end > 0) { sum += c[end]; end -= lowbit(end); } // cout<<"00000000000000000000000"<<endl; return sum; } int plus(int place,int value) { while(place < MAXN) { c[place] += value; place += lowbit(place); } return 0; }