Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
自认为自己的代码风格还是不错的,所以来贴一贴!!!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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator