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

用C++ Output Limit Exceeded用G++交就过了。。。什么原因,贴代码求解释!!!

Posted by swust20115290 at 2012-09-14 10:46:44
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int ans[100000][2],num;
struct node
{
	int l,r,cov;
	bool xo;
	int mid(){ return (l+r)>>1; }
}T[65535*2*5];
void bulit(int l,int r,int root)
{
	T[root].l=l;T[root].r=r;
	T[root].xo=false;
	T[root].cov=0;//初始化
	if(l==r)
		return ;
	int mid=T[root].mid();
	bulit(l,mid,root<<1);
	bulit(mid+1,r,root<<1|1);
}
void down(int root)//
{
	if(T[root].l==T[root].r)
		return ;
	if(T[root].cov!=-1)
	{
		T[root<<1].cov=T[root<<1|1].cov=T[root].cov;
		T[root<<1].xo=T[root<<1|1].xo=false;
		T[root].cov=-1;
	}
	else if(T[root].xo)
	{		
		if(T[root<<1].cov!=-1)
		{
			T[root<<1].cov=!T[root<<1].cov;
			T[root<<1].xo=false;
		}
		else
			T[root<<1].xo=!T[root<<1].xo;
		if(T[root<<1|1].cov!=-1)
		{
			T[root<<1|1].cov=!T[root<<1|1].cov;
			T[root<<1|1].xo=false;
		}
		else 
			T[root<<1|1].xo=!T[root<<1|1].xo;
		T[root].xo=false;
	}
}
void update(int l,int r,int root,int c)
{
	if(T[root].l==l&&T[root].r==r)
	{
		T[root].cov=c;
		if(T[root].xo)
			T[root].xo=false;
		down(root);
		return ;
	}
	down(root);
	int mid=T[root].mid();
	if(r<=mid)
		update(l,r,root<<1,c);
	else if(l>mid)
		update(l,r,root<<1|1,c);
	else
	{
		update(l,mid,root<<1,c);
		update(mid+1,r,root<<1|1,c);
	}
}
void update_xo(int l,int r,int root)
{
	if(T[root].l==l&&T[root].r==r)
	{
		if(T[root].cov!=-1)
		{
			T[root].xo=false;
			T[root].cov=!T[root].cov;
		}
		else
			T[root].xo=!T[root].xo;//还需要继续向下查找。
		down(root);
		return ;
	}
	down(root);
	int mid=T[root].mid();
	if(r<=mid)
		update_xo(l,r,root<<1);
	else if(l>mid)
		update_xo(l,r,root<<1|1);
	else
	{
		update_xo(l,mid,root<<1);
		update_xo(mid+1,r,root<<1|1);
	}
}
void find(int root)
{
	if(T[root].cov==1)
	{
		if(num>=1&&ans[num-1][1]+1==T[root].l)
			ans[num-1][1]=T[root].r;
		else
		{
			ans[num][0]=T[root].l;
			ans[num++][1]=T[root].r;
		}
		down(root);
		return ;
	}
	if(T[root].l==T[root].r||T[root].cov==0)
		return ;
	down(root);
	find(root<<1);
	find(root<<1|1);
}
int main()
{
	char op[2],z,y,i;
	int st,en;
	bulit(0,65535*2,1);
	memset(ans,0,sizeof(ans));
	while(scanf("%s %c%d,%d%c",op,&z,&st,&en,&y)!=EOF)
	{
		getchar();
		st=st*2;en=en*2;
		if(y==')') en--;
		if(z=='(') st++;
		if(st>en) continue;
		if(op[0]=='U')  
			update(st,en,1,1);
		else if(op[0]=='I') 
		{
			if(st-1>=0)	
				update(0,st-1,1,0);
			if(en+1<=65535*2)
				update(en+1,65535*2,1,0);
		}
		else if(op[0]=='D') 
			update(st,en,1,0);
		else if(op[0]=='C')
		{
			update_xo(st,en,1);
			if(st-1>=0)
				update(0,st-1,1,0);
			if(en+1<=65535*2)
				update(en+1,65535*2,1,0);
		}
		else   update_xo(st,en,1);
	}
	num=0;
	find(1);
	for(i=0;i<num;i++)
	{
		if(ans[i][0]%2==0)
			printf("[");
		else
			printf("(");
		printf("%d,",ans[i][0]/2);
		if(ans[i][1]%2==0)
			printf("%d]",(ans[i][1]/2));
		else
			printf("%d)",(ans[i][1]/2)+1);
		if(i!=num-1)
			printf(" ");
	}
	if(num==0)
		puts("empty set");
	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