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

想学着大牛们思路写……WA了……大牛们有空给抓抓BUG好么……

Posted by lalanana12345 at 2009-08-17 22:13:32 on Problem 2104
#include "iostream"
#include "string.h"
#include "stdio.h"
using namespace std;

int mmmm[20][10010];
int data[10010];
struct node
{
	int l,r;
	node operator += (const node& other)
	{	l+=other.l;	r+=other.r;	return *this;	}
};

class tree
{
public:
	tree()
	{}
	void build(int n)
	{	build(0,1,n,0);	}
	node count(int k,const int& l,const int& r,const int& key,int depth)
	{
		node ans;
		if(a[k].l==a[k].r)
		{
			ans.l=0;
			ans.r=0;
			if(mmmm[depth][a[k].l]<key)
				ans.l++;
			else if(mmmm[depth][a[k].l]>key)
				ans.r++;
		}
		else if(a[k].l>=l&&a[k].r<=r)
		{
			if(mmmm[depth][a[k].r]<key)
			{
				ans.l=a[k].r-a[k].l+1;
				ans.r=0;
				return ans;
			}
			if(mmmm[depth][a[k].l]>key)
			{
				ans.r=a[k].r-a[k].l+1;
				ans.l=0;
				return ans;
			}
			int ll=a[k].l,rr=a[k].r;
			int m;
			while(ll<rr)
			{
				m=(ll+rr)>>1;
				if(mmmm[depth][m]<key&&mmmm[depth][m+1]>=key)
				{
					ll=m;	
					break;
				}
				else if(mmmm[depth][m]>=key)
					rr=m;
				else
					ll=m+1;
			}
			if(mmmm[depth][ll]<key)
				ans.l=ll-a[k].l+1;
			else 
				ans.l=ll-a[k].l;
			rr=a[k].r;
			while(ll<rr)
			{
				m=(ll+rr)>>1;
				if(mmmm[depth][m]<=key&&mmmm[depth][m+1]>key)
				{
					rr=m+1;	
					break;
				}
				else if(mmmm[depth][m]>key)
					rr=m-1;
				else
					ll=m+1;
			}
			if(mmmm[depth][rr]>key)
				ans.r=a[k].r-rr+1;
			else
				ans.r=a[k].r-rr;
		}
		else 
		{
			ans.l=ans.r=0;
			int m=(a[k].l+a[k].r)>>1;
			if(l<=m)
				ans+=count(lson(k),l,r,key,depth+1);
			if(r>m)
				ans+=count(rson(k),l,r,key,depth+1);
		}
		return ans;
	}
private:
	void build(int k,int l,int r,int d)
	{
		a[k].l=l;
		a[k].r=r;
		if(l==r)
		{
			mmmm[d][l]=data[l];
		}
		else
		{
			int ls=lson(k),rs=rson(k),m=(l+r)>>1;
			build(ls,l,m,d+1);
			build(rs,m+1,r,d+1);
			int i=l,j=m+1,k=l;
			while(i<=m&&j<=r)
			{
				if(mmmm[d+1][i]<=mmmm[d+1][j])
					mmmm[d][k++]=mmmm[d+1][i++];
				else
					mmmm[d][k++]=mmmm[d+1][j++];
			}
			while(i<=m)
				mmmm[d][k++]=mmmm[d+1][i++];
			while(j<=r)
				mmmm[d][k++]=mmmm[d+1][j++];
		}
	}
	inline int lson(int i)
	{	return (i<<1)+1;		}
	inline int rson(int i)
	{	return (i<<1)+2;		}
	inline int father(int i)
	{	return (i-1)>>1	;	}
	node a[270000];
}ttt;




int main()
{
	int n,m,a,b,k,l,r,mid,len;
	node c;
	cin>>n>>m;
	int i,j;
	for(i=1;i<=n;i++)
	{
		get(data[i]);
	}
	ttt.build(n);
	for(;m;--m)
	{
		scanf("%d%d%d",&a,&b,&k);
		l=1;	r=n;
		k--;
		len=b-a;
		while(l<r)
		{
			mid=(l+r)>>1;
			c=ttt.count(0,a,b,mmmm[0][mid],0);
			if(c.l==k&&c.l+c.r==len)
			{
				l=mid;
				break;
			}
			else if(c.l<k||c.r>len-k)
				l=mid+1;
			else 
				r=mid-1;
		}
		printf("%d\n",mmmm[0][l]);
		

	}
	
	//system("pause");
	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