Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

树状数组ac~

Posted by yueyibo at 2016-10-23 17:07:50 on Problem 2352
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator