ZOJ1610【未完成】

以下代碼是錯的,僅用於存儲而用

#include<iostream>
#include<cstdio>
#include<cstring>
const int maxn=8000+10;
#define mid ((s+t)>>1)  
#define ls h<<1,s,mid  
#define rs h<<1|1,mid+1,t 
using namespace std;
struct node{
	int c,sc,tc;
};
node a[maxn<<2];
int sum[maxn];
void init(int h,int s,int t ){
	if(s==t){
		a[h].c=10000;a[h].sc=a[h].tc=10000;
	}else{
		init(ls);
		init(rs);
		a[h].c=10000;a[h].sc=a[h].tc=10000;
	}

}
void ts(int h,int s,int t,int L,int R,int ys){
	if(L<=s && t<=R){
		a[h].c=ys;a[h].sc=a[h].tc=ys;
	}else{
		if(a[h].c>=0){
			a[h<<1].c=a[h<<1|1].c=a[h].c;
			a[h].c=-1;
		}
		if(L<=mid)ts(ls,L,R,ys);
		if(mid<R)ts(rs,L,R,ys);			
		a[h].sc=a[h<<1].sc;a[h].tc=a[h<<1|1].tc;	
	}
}
void dfs(int h,int s,int t){
	if(s<t){
		if(a[h].c!=-1){
			a[h<<1].c=a[h<<1|1].c=a[h].c;			
		}
		dfs(ls);
		dfs(rs);
	}
}
void cal(int h,int s,int t){
	printf("%d %d %d %d\n",h,a[h].c,s,t);
	if((s==t)){
		sum[a[h].c]++;		
	}
	else{
		cal(ls);
		cal(rs);
		if(a[h<<1].tc==a[h<<1|1].sc)sum[a[h<<1].tc]--;
	}
}
int main(){
	int i,j,k,m,n,x,y,z;
	while(scanf("%d",&n)!=EOF){
		memset(sum,0,sizeof(sum));
		init(1,1,6);
		for(i=1;i<=n;i++){
			scanf("%d%d%d",&x,&y,&z);			
			ts(1,1,4,x+1,y,z);
		}
		cout<<endl;
		dfs(1,1,6);
		cal(1,1,6);
		for(i=0;i<=8000;i++)
			if(sum[i])printf("%d %d\n",i,sum[i]);
		
	}
	return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章