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

把我的TLE代码贴出来吧。。。

Posted by shiroi at 2007-05-16 00:38:12 on Problem 3225
In Reply To:报告里面 whether membership is inverted in this interval 这句话该怎么理解呢?TLE无数次,请指教 Posted by:shiroi at 2007-05-15 23:13:21
#include<stdio.h>
#define maxn 65600

struct seg{
	int ll,rr,cov;
	seg(int l=0,int r=0,int ccov=-1)	{	ll=l,rr=r,cov=ccov;}
}segt[8*maxn];
seg ans[maxn];
int size=0;
void build(int l,int r,int ind)
{
	segt[ind].ll=l;	segt[ind].rr=r;	segt[ind].cov=-1;
	if(r-l>1)	{
		int mid=(l+r)/2;
		build(l,mid,ind+ind);
		build(mid,r,ind+ind+1);
	}
}
void segunion(int l,int r,int ind)
{
	if(segt[ind].cov!=1)	{
		if(l<=segt[ind].ll&&r>=segt[ind].rr)	{
			segt[ind].cov=1;	return ;
		}
		if(segt[ind].rr-segt[ind].ll>1)	{
			if(segt[ind].cov==-1)
				segt[ind].cov=0;	
			if(l<(segt[ind].ll+segt[ind].rr )/2)	segunion(l,r,ind+ind);
			if(r>(segt[ind].ll+segt[ind].rr )/2)	segunion(l,r,ind+ind+1);
		}
	}
}
void segsub(int l,int r,int ind)	
{
	if(segt[ind].cov!=-1)	{
		if(l<=segt[ind].ll&&r>=segt[ind].rr)	{
			segt[ind].cov=-1;	return ;
		}
		if(segt[ind].rr-segt[ind].ll>1)	{
			if(segt[ind].cov==1)	
				segt[ind+ind].cov=segt[ind+ind+1].cov=1;	
			if(l<(segt[ind].ll+segt[ind].rr)/2)	segsub(l,r,ind+ind);
			if(r>(segt[ind].ll+segt[ind].rr)/2)	segsub(l,r,ind+ind+1);
			if(segt[ind+ind].cov*segt[ind+ind+1].cov==1)
				segt[ind].cov=segt[ind+ind].cov;
			else segt[ind].cov=0;
		}
	}
}
void segxor(int l,int r,int ind)
{
	if(segt[ind].cov!=0)	{
		if(l<=segt[ind].ll&&r>=segt[ind].rr)	{
			segt[ind].cov=-segt[ind].cov;	return ;
		}
		if(segt[ind].rr-segt[ind].ll>1)	{
			segt[ind+ind].cov=segt[ind+ind+1].cov=segt[ind].cov;	segt[ind].cov=0;
			if(l<(segt[ind].ll+segt[ind].rr)/2)	segxor(l,r,ind+ind);
			if(r>(segt[ind].ll+segt[ind].rr)/2)	segxor(l,r,ind+ind+1);
		}
	}
	else {
		if(l<=segt[ind].ll&&r>=segt[ind].rr&&segt[ind].rr-segt[ind].ll>1)	{
			if(l<(segt[ind].ll+segt[ind].rr)/2)	segxor(l,r,ind+ind);
			if(r>(segt[ind].ll+segt[ind].rr)/2)	segxor(l,r,ind+ind+1);
			return ;
		}
		else if(segt[ind].rr-segt[ind].ll>1)	{
			if(l<(segt[ind].ll+segt[ind].rr)/2)	segxor(l,r,ind+ind);
			if(r>(segt[ind].ll+segt[ind].rr)/2)	segxor(l,r,ind+ind+1);
			if(segt[ind+ind].cov*segt[ind+ind+1].cov==1)
				segt[ind].cov=segt[ind+ind].cov;
			else segt[ind].cov=0;
		}
	}
}
void stat(int ind)
{
	if(segt[ind].cov==1)	{
		if(size==0)	ans[size++]=seg(segt[ind].ll,segt[ind].rr);
		else {
			if(segt[ind].ll<=ans[size-1].rr)	
				ans[size-1].rr=segt[ind].rr;
			else ans[size++]=seg(segt[ind].ll,segt[ind].rr);
		}
		return ;
	}
	else if(segt[ind].cov==-1)	return ;
	if(segt[ind].rr-segt[ind].ll>1)	{
		stat(ind+ind);	stat(ind+ind+1);
	}
}
int main()
{
	char cmd,bra1,bra2,dot;	
	int a,b;
	build(0,2*65535+1,1);
	while(scanf("%c %c%d,%d%c\n",&cmd,&bra1,&a,&b,&bra2)==5)	{
		if(bra1=='[')	a=a+a;	else a=a+a+1;
		if(bra2==']')	b=b+b+1;	else b=b+b;
		if(cmd=='U'&&b>a)		
			segunion(a,b,1);
		else if(cmd=='I'&&b>a)	{
			if(a>0)	
				segsub(0,a,1);	
			if(b<2*65535+1)
				segsub(b,2*65535+1,1);
		}
		else if(cmd=='D'&&b>a)	
			segsub(a,b,1);
		else if(cmd=='C'&&b>a)	{	
			if(a>0)
				segsub(0,a,1);
			if(b<2*65535+1)
				segsub(b,2*65535+1,1);	
			if(b>a)
				segxor(a,b,1);
		}
		else if(cmd=='S'&&b>a)		
			segxor(a,b,1);
	}
	stat(1);
	if(size==0)	{
		printf("empty set\n");	return 0;
	}
	for(a=0;a<size-1;a++)	{
		if(ans[a].ll%2==0)	printf("[%d,",ans[a].ll/2);
		else printf("(%d,",ans[a].ll/2);
		if(ans[a].rr%2==0)	printf("%d) ",ans[a].rr/2);
		else printf("%d] ",ans[a].rr/2);
	}
	if(ans[a].ll%2==0)	printf("[%d,",ans[a].ll/2);
		else printf("(%d,",ans[a].ll/2);
	if(ans[a].rr%2==0)	printf("%d)\n",ans[a].rr/2);
		else printf("%d]\n",ans[a].rr/2);
	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