Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
树状数组ac~http://blog.csdn.net/luckcircle/article/details/52901371 有什么不懂的戳上面链接,也欢迎留言交流~ #include<stdio.h> #include<string.h> int level[15002]; int tree[32001]; int getsum(int k) { int sum=0; while(k) { sum+=tree[k]; k-=k&-k; } return sum; } void add(int k,int num) { while(k<=32001) { tree[k]+=num; k+=k&-k; } } int main(){ int t,i,x,y; scanf("%d",&t); memset(level,0,sizeof(level)); memset(tree,0,sizeof(tree)); for(i=0;i<t;i++){ scanf("%d %d",&x,&y); add(x+1,1); level[getsum(x+1)-1]++; } for(i=0;i<t;i++){ printf("%d\n",level[i]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator