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 求大牛指点

Posted by zhuli102232 at 2010-05-18 21:51:16 on Problem 2777
#include <iostream>
using namespace std;
struct tree{
	int left;
	int right;
	int color;
}T[300005];
int ans;
bool colors[35];

void BT(int r,int  a,int b){
	T[r].left=a;
	T[r].right=b;
	T[r].color=1;
	if(a==b) return ;
	int mid=(a+b)>>1;
	BT(2*r,a,mid);
	BT(2*r+1,mid+1,b);
}

void insert(int r,int a,int b,int c){
	if(T[r].left==a &&T[r].right==b ){
		T[r].color=c;
		return ;
	}
	if(T[r].color!=c){
    	if(T[r].color){
		T[2*r].color=T[r].color;
		T[2*r+1].color=T[r].color;
		T[r].color=0;
		}
	}
	else{
		return ;
	}
	int mid=(T[r].left+T[r].right)>>1;
	if(b<=mid){
		insert(2*r,a,b,c);//
	}
	else {
		if(a>mid){
			insert(2*r+1,a,b,c);//
		}
		else{
			insert(2*r,a,mid,c);
			insert(2*r+1,mid+1,b,c);
		}
	}
}

void visit(int r,int a,int b){
	if(T[r].left==a && T[r].right==b && T[r].color){
		if(colors[T[r].color]){
			ans++;
			colors[T[r].color]=false;
		}
		return ;
	}
    int mid=(T[r].left+T[r].right)>>1;
	if(b<=mid){
		visit(2*r,a,b);
	}
	else{
		if(a>mid){
			visit(2*r+1,a,b);
		}
		else{
			visit(2*r,a,mid);
			visit(2*r+1,mid+1,b);
		}
	}
}

int main(){
	int t,n,o,a,b,c,max,min;
	char x;
    while(scanf("%d%d%d",&n,&t,&o)!=EOF){
		BT(1,1,n);
		while(o--){
			scanf("%c%c",&x,&x);
			if(x=='C'){
				scanf("%d%d%d",&a,&b,&c);
				max=a>b?a:b;
				min=a<b?a:b;
				insert(1,min,max,c);
			}
			else{
				scanf("%d%d",&a,&b);
				max=a>b?a:b;
				min=a<b?a:b;
				ans=0;
				memset(colors,true,sizeof(colors));
				visit(1,min,max);
				printf("%d\n",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