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

Why wrong ??????????????

Posted by dq at 2008-09-05 16:49:16 on Problem 2777
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
struct node
{
	int l,r,col;
	int lch,rch;
}way[400000];
int top;
void build(int cnt,int left,int right)
{
	int mid;
	way[cnt].l=left,way[cnt].r=right;
	way[cnt].col=1;
	if(left==right) return ;
	mid=(left+right)>>1;
	way[cnt].lch=++top;
	build(top,left,mid);
	way[cnt].rch=++top;
	build(top,mid+1,right);
}
int single(int a)
{
	return a&(a-1)==0;
}
void setcolour(int cnt,int left,int right,int colour)
{
	if(left<way[cnt].l)
		left=way[cnt].l;
	if(right>way[cnt].r)
		right=way[cnt].r;
	if(left>right) return ;
	if(way[cnt].l==left&&way[cnt].r==right)
	{
		way[cnt].col=colour;
		return ;
	}
	if(way[cnt].col==colour) return ;
	if(single(way[cnt].col))
	{
		way[way[cnt].lch].col=way[cnt].col;
		way[way[cnt].rch].col=way[cnt].col;
	}
	setcolour(way[cnt].lch,left,right,colour);
	setcolour(way[cnt].rch,left,right,colour);
	way[cnt].col=way[way[cnt].lch].col|way[way[cnt].rch].col;
}
int getcolour(int cnt,int left,int right)
{
	int colour=0;
	if(left<way[cnt].l)
		left=way[cnt].l;
	if(right>way[cnt].r)
		right=way[cnt].r;
	if(left>right) return 0;
	if(left==way[cnt].l&&right==way[cnt].r)
		return way[cnt].col;
	colour|=getcolour(way[cnt].lch,left,right);
	colour|=getcolour(way[cnt].rch,left,right);
	return colour;
}
int calcolor(int cnt)
{
	int ans=0;
	while(cnt>0)
	{
		ans+=cnt%2;
		cnt/=2;
	}
	return ans;
}
int main()
{
	int L,T,O,left,right,colour,i,ans;
	char AC;
	scanf("%d %d %d",&L,&T,&O);
	top=0;
	build(0,1,L);
	for(i=0;i<O;i++)
	{
		scanf(" %c",&AC);
		if(AC=='C')
		{
			scanf("%d %d %d",&left,&right,&colour);
			if(left>right)
				swap(left,right);
			setcolour(0,left,right,1<<(colour-1));
		}
		else
		{
			scanf("%d %d",&left,&right);
			if(left>right) swap(left,right);
			ans=getcolour(0,left,right);
			printf("%d\n",calcolor(ans));
		}
	}
	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