QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1038#660269#21672. 【NOIP Round #1】冲塔wth2026max666dong123Failed.2024-10-21 20:25:302024-10-21 20:25:31

Details

Extra Test:

Accepted
time: 744ms
memory: 296480kb

input:

1000000
790142 227746
571659 781699
217044 778057
961348 206921
629031 143387
63496 891845
918782 507511
853207 398951
450037 497086
542590 962826
177615 20465
893303 23139
595267 674428
254817 503779
860762 391370
233869 171097
450396 150281
495440 902720
353740 959593
962826 794903
579161 137567
8...

output:

000000000000000000000000000000000000000000001000000000000000000000000000000100000000000000000000000000000000000000000001000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000...

result:

ok ok

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#660269#21672. 【NOIP Round #1】冲塔max666dong123100 ✓2091ms405772kbC++145.5kb2024-10-20 09:51:572024-10-20 09:51:58

answer

#include<bits/stdc++.h>
#define int long long 
using namespace std;
const int N=2e6+10;
namespace TEST3{
	const int N=2e6+10;
	int n;
	struct node{
		int x,y;
		int i;
	}a[N];
	map<int,int>mp;
	vector<int>b;
	int idx;
	struct NODE{
		int y;
		int i;
	};
	list<NODE>row[N];
	int line[N][2];
	int len[N];
	bool ans[N];
	void del(int r,int pos){
		if(pos==1){
			len[row[r].front().y]--;
			row[r].pop_front();
		}
		else{
			len[row[r].back().y]--;
			row[r].pop_back();
		}
		if(row[r].size()<=1){
			return;
		}
		list<NODE>::iterator it;
		if(pos==1){
			it=row[r].begin();
		}
		else{
			it=row[r].end();it=next(it,-1);
		}
		if(len[it->y]<=1){
			line[it->y][++len[it->y]]=r;
		}
		else{
			int pos=1;
			if(row[line[it->y][2]].front().y==it->y){
				
			}
			else{
				pos=2;
			}
			del(line[it->y][2],pos);
			line[it->y][++len[it->y]]=r;
		}
	}
	bool cmp(node x,node y){
		return x.x<y.x||(x.x==y.x&&x.y<y.y);
	}
	signed main(){
//	freopen("tower.in","r",stdin);
//	freopen("tower.out","w",stdout);
//		scanf("%lld",&n);
		for(int i=1;i<=n;i++){
//			scanf("%lld%lld",&a[i].x,&a[i].y);
			b.push_back(a[i].x);
			b.push_back(a[i].y);
			a[i].i=i;
		}
		sort(b.begin(),b.end());
		for(int x:b){
			if(mp[x]){
				continue;
			}
			mp[x]=++idx;
		}
		for(int i=1;i<=n;i++){
			a[i].x=mp[a[i].x];
			a[i].y=mp[a[i].y];
//		cout<<a[i].y<<" "<<i<<endl;
		}
		sort(a+1,a+1+n,cmp);
		for(int i=1;i<=n;i++){
			row[a[i].x].push_back({a[i].y,a[i].i});
		}
		for(int i=1;i<=idx;i++){
			if(row[i].size()<=0){
				continue;
			}
			list<NODE>::iterator it=row[i].begin();
			if(len[it->y]<=1){
				line[it->y][++len[it->y]]=i;
			}
			else{
				int pos=1;
				if(row[line[it->y][2]].front().y==it->y){
					
				}
				else{
					pos=2;
				}
				del(line[it->y][2],pos);	
				line[it->y][++len[it->y]]=i;
			}
			if(row[i].size()<=1){
				continue;
			}
			it=row[i].end();it=next(it,-1);
			if(len[it->y]<=1){
				line[it->y][++len[it->y]]=i;
			}
			else{
				int pos=1;
				if(row[line[it->y][2]].front().y==it->y){
					
				}
				else{
					pos=2;
				}
				del(line[it->y][2],pos);		
				line[it->y][++len[it->y]]=i;
			}
		}
		for(int i=1;i<=idx;i++){
			if(row[i].size()<=0){
				continue;
			}
			ans[row[i].front().i]=1;
			ans[row[i].back().i]=1;
		}
		for(int i=1;i<=n;i++){
			cout<<ans[i];
		}
		return 0;
	}
}
int n;
struct node{
	int x,y;
	int i;
}a[N];
map<int,int>mp;
int fmp[N];
vector<int>b;
int idx;
struct NODE{
	int y;
	int i;
};
list<NODE>row[N];
set<int>line[N];
int ans[N];
bool cmp(node x,node y){
	return (x.x<y.x)||(x.x==y.x&&x.y<y.y)||(x.x==y.x&&x.y==y.y&&x.i<y.i);
}
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&a[i].x,&a[i].y);
		b.push_back(a[i].x);
		b.push_back(a[i].y);
		a[i].i=i;
	}
	int maxx=0;
	int maxy=0;
	for(int i=1;i<=n;i++){
		maxx=max(maxx,a[i].x);
		maxy=max(maxy,a[i].y);
	}
	if(maxx*maxy==n){
//		cout<<"YES\n";
		TEST3::n=n;
		for(int i=1;i<=n;i++){
			TEST3::a[i].i=a[i].i;
			TEST3::a[i].x=a[i].x;
			TEST3::a[i].y=a[i].y;
		}
		TEST3::main();
		return 0;
	}
	sort(b.begin(),b.end());
	for(int x:b){
		if(mp[x]){
			continue;
		}
		mp[x]=++idx;
		fmp[idx]=x;
	}
	for(int i=1;i<=n;i++){
		a[i].x=mp[a[i].x];
		a[i].y=mp[a[i].y];
//		cout<<a[i].x<<" "<<a[i].y<<endl;
	}
	sort(a+1,a+1+n,cmp);
	int min1=LONG_LONG_MAX;
	for(int i=1;i<=n;i++){
		row[a[i].x].push_back({a[i].y,a[i].i});
//		min1=min(min1,a[i].y);
	}
	for(int i=1;i<=idx;i++){
		if(row[i].size()<=0){
			continue;
		}
		min1=min(min1,row[i].front().y);
	}
	
	for(int i=1;i<=idx;i++){
		if(row[i].size()<=0){
			continue;
		}
		list<NODE>::iterator it=row[i].begin();
		line[it->y].insert(i);
		if(row[i].size()<=1){
			continue;
		}
		it=row[i].end();it=next(it,-1);
		line[it->y].insert(i);
	}
	while(1){
		int cnt=0;
		for(int i=idx;i>=1;i--){
//		if(i==min1){
//			if(line[i].size()<=2){
//				break;
//			}
//			for(set<int>::iterator it=next(line[i].begin(),1);it!=next(line[i].end(),-1);it++){
//				row[*it].pop_front();
////				cout<<i<<" "<<" - "<<(*it)<<endl;
////				if(row[*it].size()>=2){
////					line[row[*it].back().y].insert(*it);
////				}
//			}	
//			break;
//		}
			vector<int>er;
			if(line[i].size()>2){
//				cout<<j<<" "<<line[i].size()<<endl;
				for(set<int>::iterator it=next(line[i].begin(),1);it!=next(line[i].end(),-1);it++){
					er.push_back(*it);
					if(row[*it].back().y==i){
						row[*it].pop_back();
						if(row[*it].size()>=2){
							line[row[*it].back().y].insert(*it);
							cnt++;
						}	
					}
					else{
						row[*it].pop_front();	
						if(row[*it].size()>=2){
							line[row[*it].front().y].insert(*it);
							cnt++;
						}
					}
//				cout<<i<<" "<<" - "<<(*it)<<endl;
					
				}
//			len[i]=2;
			}
			for(int x:er){
				line[i].erase(x);
			}
		}	
		if(!cnt){
			break;
		}
	}
	
	for(int i=1;i<=idx;i++){
		if(row[i].size()<=0){
			continue;
		}
		ans[row[i].front().i]=1;
		ans[row[i].back().i]=1;
	}
	for(int i=1;i<=idx;i++){
		if(row[i].size()<=0){
			continue;
		}
//		cout<<i<<" "<<row[i].front().y<<" A"<<endl;
//		cout<<i<<" "<<row[i].back().y<<" A"<<endl;
//		ans[row[i].front().i]=1;
//		ans[row[i].back().i]=1;
	}
//	cout<<len[1]<<endl;
	for(int i=1;i<=n;i++){
//		cout<<ans[i];
		printf("%lld",ans[i]);
	}
	
	return 0;
}
/*
11
4 2 
1 2 
1 1 
3 3 
2 1 
4 1 
2 3 
2 4 
1 4 
4 3 
3 4 

*/