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

贴个线段树的代码,知道怎么用二叉检索树做的朋友告诉我一声,谢谢了。

Posted by ljfljf2006 at 2009-08-30 12:03:06 on Problem 2352
#include <iostream>
using namespace std;
const int maxn=32005;
int tree[maxn*8],ans[15000];
int Search(int i,int x,int left=0,int right=maxn)
{
	tree[i]++;
	if(x==right) return tree[i]-1;//把自己减掉
	int mid=(left+right)/2;
	if(x<=mid) return Search(i*2,x,left,mid);
	else return tree[i*2]+Search(i*2+1,x,mid+1,right);
}
int main()
{
	int n,x,y;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		ans[Search(1,x)]++;
	}
	for(int i=0;i<n;i++)
		printf("%d\n",ans[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