今天继续公布用线段树攻克2352 的方法:
题意昨天已经说过了,直接贴代码!
code:
# include<stdio.h> int a[32000*4]; int level[15002]; int Search(int step,int x,int left,int right) { a[step]++; if(x==right) return a[step]-1; int mid=(left+right)/2; if(x<=mid) return Search(2*step,x,left,mid); else return a[step*2]+Search(2*step+1,x,mid+1,right); ///左边子树加上右边子树的左子树 } int main() { int i,n,x,y; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) { scanf("%d%d",&x,&y); level[Search(1,x,0,32001)]++; } for(i=0;i<n;i++) printf("%d\n",level[i]); } return 0; }