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

和kuangbin的程序拍了好久,求一组hack数据

Posted by sola_165 at 2017-07-23 13:54:48 on Problem 3225
#include<iostream>
#include<cstdio>
#include<cstring>
#define M 400010
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define Mid (l+r)>>1
using namespace std;
struct tree{
	int cov,yh;
}Tree[M<<2];
bool mark[M];
void up(int rt){
	if(Tree[rt<<1].cov==1&&Tree[rt<<1|1].cov==1)Tree[rt].cov=1;
	else if(Tree[rt<<1].cov==0&&Tree[rt<<1|1].cov==0)Tree[rt].cov=0;
	else Tree[rt].cov=-1;
}
void build(int l,int r,int rt){
	if(l==r){
		Tree[rt].cov=Tree[rt].yh=0;
		return ;
	}int mid=Mid;
	build(lson);
	build(rson);
	up(rt);
}
void down(int rt){
	if(Tree[rt].yh){
		if(Tree[rt<<1].cov==-1)Tree[rt<<1].yh^=1;
		else Tree[rt<<1].cov^=1;
		if(Tree[rt<<1|1].cov==-1)Tree[rt<<1|1].yh^=1;
		else Tree[rt<<1|1].cov^=1;
		Tree[rt].yh=0;
	}
	if(Tree[rt].cov==1||Tree[rt].cov==0){
		Tree[rt<<1].cov=Tree[rt].cov;
		Tree[rt<<1|1].cov=Tree[rt].cov;
	}
}
void clean(int L,int R,int x,int l,int r,int rt){
	if(L==l&&R==r){
		Tree[rt].cov=x;
		Tree[rt].yh=0;
		return ;
	}down(rt);
	int mid=Mid;
	if(R<=mid)clean(L,R,x,lson);
	else if(L>mid)clean(L,R,x,rson);
	else clean(L,mid,x,lson),clean(mid+1,R,x,rson);

	up(rt);
}
void yh(int L,int R,int l,int r,int rt){
	if(L==l&&R==r){
		if(Tree[rt].cov==-1)Tree[rt].yh^=1;
		else Tree[rt].cov^=1;
		return ;
	}down(rt);
	int mid=Mid;
	if(R<=mid)yh(L,R,lson);
	else if(L>mid)yh(L,R,rson);
	else yh(L,mid,lson),yh(mid+1,R,rson);
	up(rt);
}
void query(int l,int r,int rt){
	if(Tree[rt].cov==1){
		for(int i=l;i<=r;i++)
			mark[i]=1;
		return ;
	}
	if(l==r)return;
	down(rt);
	int mid=Mid;
	query(lson);
	query(rson);
}
int get_num(int flag,int x,int t){
	if(flag)return (x+1)*2;
	else{ 
		if(t)return (x+1)*2-1;
		else return (x+1)*2+1;
	}
}
void debug(int l,int r,int rt){
	cout<<l<<" "<<r<<" : "<<Tree[rt].cov<<" "<<Tree[rt].yh<<endl;
	if(l==r)return;
	int mid=Mid;
	debug(lson);
	debug(rson);
}
const int Max=(100000<<1);
void print(){
	bool pd=1,flag=1,temp=0;
	for(int i=1;i<=Max;i++){
		if(mark[i])flag=0;
		if(mark[i]){
			if(pd){
				if(temp)cout<<" ";
				else temp=1;
				if(i%2)cout<<"("<<i/2-1<<",";
				else cout<<"["<<i/2-1<<",";
				pd=0;
			}
		}
		if(!mark[i+1]&&!pd){
			if(i%2)cout<<i/2<<")";
			else cout<<i/2-1<<"]";
			pd=1;
		}
	}
	if(flag){
		cout<<"empty set";
	}
	cout<<endl;
}
void solve(){
	char s[10];
	build(1,Max,1);
	int Case=0;
	while(~scanf("%s",s)){
		char q[10];
		scanf("%s",q);
		int l,r;
		bool flag1=0,flag2=0;
		if(q[0]=='[')flag1=1;
		if(q[strlen(q)-1]==']')flag2=1;
		if(flag1)sscanf(q,"[%d,%d",&l,&r);
		else sscanf(q,"(%d,%d",&l,&r);
		l=get_num(flag1,l,0);
		r=get_num(flag2,r,1);
		if(s[0]=='U'){
			if(l>r)continue;
			clean(l,r,1,1,Max,1);
		}else if(s[0]=='I'){
			if(l>r)clean(1,Max,0,1,Max,1);
			else{
				clean(1,l-1,0,1,Max,1);
				clean(r+1,Max,0,1,Max,1);
			}
		}else if(s[0]=='D'){
			if(l>r)continue;
			clean(l,r,0,1,Max,1);
		}else if(s[0]=='C'){
			if(l>r)clean(1,Max,0,1,Max,1);
			else{
				yh(l,r,1,Max,1);
				clean(1,l-1,0,1,Max,1);
				clean(r+1,Max,0,1,Max,1);
			}
		}else{
			if(l>r)continue;
			yh(l,r,1,Max,1);
		}
		
	}
	memset(mark,0,sizeof(mark));
	query(1,Max,1);
	print();
	/*for(int i=1;i<=Max;i++)
		if(mark[i])cout<<i<<" ";
	cout<<endl;*/
}
int main(){
	solve();
	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