| ||||||||||
| 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 | |||||||||
贴个线段树的代码,知道怎么用二叉检索树做的朋友告诉我一声,谢谢了。#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator