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

What the hell is wrong here?

Posted by waltdizuni at 2010-01-20 10:59:58 on Problem 2777
#include<cstdio>
struct asdf{
	int code,l,r,cont;
}arr[263000];
int n,t,o,lim,x,y,z;
void color(int p){
	if(x<=arr[p].l&&arr[p].r<=y){
		arr[p].code=(1<<z); arr[p].cont=0;
		return;
	}
	else if(y<arr[p].l||arr[p].r<x) return;
	else{
		color(p*2);
		color(p*2+1);
		arr[p].code=arr[p*2].code|arr[p*2+1].code;
		arr[p].cont=(arr[p*2].cont|arr[p*2+1].cont)||(arr[p*2].code!=arr[p*2+1].code);
	}
}
void count(int p){
	if(x<=arr[p].l&&arr[p].r<=y){
		z|=arr[p].code;
		return;
	}
	else if(y<arr[p].l||arr[p].r<x) return;
	else{
		if(!arr[p].cont){
			arr[p*2].code=arr[p*2+1].code=arr[p].code;
			arr[p*2].cont=arr[p*2+1].cont=0;
		}
		count(p*2);
		count(p*2+1);
	}
}
int main(){
	int i,j;
	char c;
	scanf("%d%d%d",&n,&t,&o);
	for(lim=1; lim<n; lim*=2);
	for(i=lim; i<2*lim; i++) arr[i].l=arr[i].r=i-lim+1,arr[i].code=1;
	for(i=lim-1; i>0; i--) arr[i].l=arr[i*2].l,arr[i].r=arr[i*2+1].r,arr[i].code=1;
	while(o--){
		scanf("\n%c",&c);
		if(c=='C'){
			scanf("%d%d%d",&x,&y,&z); z--;
			if(x>y) i=x,x=y,y=i;
			color(1);
		}
		else if(c=='P'){
			scanf("%d%d",&x,&y); z=0;
			if(x>y) i=x,x=y,y=i;
			count(1);
			for(i=0,j=0; i<t; i++){
				if(z&(1<<i)) j++;
			}
			printf("%d\n",j);
		}
	}
	return 0;
}

I used interval tree by recursive func..
I don't think it has any error on that
Please find counter input

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