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

自认为自己的代码风格还是不错的,所以来贴一贴!!!

Posted by 070220219 at 2010-10-20 15:29:01 on Problem 2777
const int MN=100010;
struct Seg{
	int left,right,col;   //col==-1,代表该区间颜色是混乱的,即不是全部一样。 
}S[MN*6];
int n,m,T,ans;
bool used[40];

inline int L(int x){return 2*x;}
inline int R(int x){return 2*x+1;}

void build(int idx,int left,int right)
{
	S[idx].left=left;
	S[idx].right=right;
	S[idx].col=-1;
	if(left<right){
		int mid=(left+right)>>1;
		build(L(idx),left,mid);
		build(R(idx),mid+1,right);
	}
}
void update(int idx,int left,int right,int col)
{
	if(left==S[idx].left && right==S[idx].right){
		S[idx].col=col;
		return ;
	}
	//col!=-1,代表该区间颜色是固定的,则更新它的孩子节点。
	if(S[idx].col!=-1){
		S[L(idx)].col=S[R(idx)].col=S[idx].col;
		S[idx].col=-1; 
	}
	int mid=(S[idx].left+S[idx].right)>>1;
	if(left>=mid+1)
		update(R(idx),left,right,col);
	else if(right<=mid)
		update(L(idx),left,right,col);
	else{
		update(L(idx),left,mid,col);
		update(R(idx),mid+1,right,col);
	}
}
void query(int idx,int left,int right)
{
	if(S[idx].col!=-1){
		if(!used[S[idx].col]){
			used[S[idx].col]=true;
			ans++;
		}
		return ;
	}
	int mid=(S[idx].left+S[idx].right)>>1;
	if(right<=mid)
		query(L(idx),left,right);
	else if(left>=mid+1)
		query(R(idx),left,right);
	else{
		query(L(idx),left,mid);
		query(R(idx),mid+1,right);
	}
}

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