QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1220#655862#21672. 【NOIP Round #1】冲塔czr2012czr2012Failed.2024-11-20 21:42:582024-11-20 21:42:59

Details

Extra Test:

Accepted
time: 12ms
memory: 146084kb

input:

8
2 1
2 2
2 3
3 3
3 2
1 3
3 4
4 2

output:

10101111

result:

ok ok

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#655862#21672. 【NOIP Round #1】冲塔czr2012100 ✓2984ms363344kbC++143.5kb2024-10-19 10:02:392024-10-19 10:02:39

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

const int maxn=1e6+10;
int n,x[maxn],y[maxn];
set<pair<int,int>>s[maxn],s2[maxn],s3[maxn];
priority_queue<int>pq; 
pair<int,int>h[maxn],t[maxn];
pair<int,int>h2[maxn],t2[maxn];
bool flag[maxn];
map<pair<int,int>,int>mp;
int maxxx,maxxx2;

signed main()
{
//	freopen("tower.in","r",stdin);
//	freopen("tower.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i]>>y[i];
		s[x[i]].insert({x[i],y[i]});
		s2[y[i]].insert({x[i],y[i]});
		mp[{x[i],y[i]}]=i;
		maxxx=max(maxxx,x[i]);
		maxxx2=max(maxxx2,y[i]);
	}
	for(int i=1;i<=maxxx;i++)
	{
//		for(pair<int,int>j:v[i])
//		{
//			cout<<mp[j]<<' ';
//		}
//		cout<<endl;
		if(s[i].size()>=1)
		{
			h[i]=*s[i].begin();
			t[i]=*s[i].rbegin();
			flag[mp[h[i]]]=true;
			flag[mp[t[i]]]=true;
		}
	}
	for(int i=1;i<=maxxx2;i++)
	{
		int cnt=0;
		for(pair<int,int>j:s2[i])
		{
			if(flag[mp[j]])
			{
				cnt++;
			}
		}
		if(cnt>=3)
		{
			int cnt2=0;
			for(pair<int,int>j:s2[i])
			{
				if(flag[mp[j]])
				{
					cnt2++;
					if(cnt2==1||cnt2==cnt)
					{
						s3[i].insert(j);
					}
				}
			}
			cnt2=0;
			for(pair<int,int>j:s2[i])
			{
				if(flag[mp[j]])
				{
					cnt2++;
					if(s3[i].find(j)==s3[i].end())
					{
						flag[mp[j]]=false;
						if(j==*s[j.first].rbegin())
						{
							s[j.first].erase(j);
							if(s[j.first].size())
							{
								flag[mp[*s[j.first].rbegin()]]=true;
								int now=s[j.first].rbegin()->second;
								s3[now].insert(*s[j.first].rbegin());
								if(now<=i)
								{
									pq.push(now);
								}
								while(pq.size())
								{
									now=pq.top();
									while(s3[now].size()>2)
									{
										pair<int,int>j=*s3[now].begin();
										j=*s3[now].upper_bound(j);
										s3[now].erase(j);
										if(s[j.first].empty())
										{
											continue;
										}
										if(j==*s[j.first].rbegin())
										{
											s[j.first].erase(j);
											flag[mp[j]]=false;
											if(s[j.first].size())
											{
												flag[mp[*s[j.first].rbegin()]]=true;
												now=s[j.first].rbegin()->second;
												s3[now].insert(*s[j.first].rbegin());
												pq.push(now);
												now=pq.top();
											}
										}
										else if(j==*s[j.first].begin())
										{
											s[j.first].erase(j);
											flag[mp[j]]=false;
											if(s[j.first].size())
											{
												flag[mp[*s[j.first].begin()]]=true;
												now=s[j.first].begin()->second;
												if(now<=i)
												{
													s3[now].insert(*s[j.first].begin());
													pq.push(now);
												}
												now=pq.top();
											}
										}
									}
									if(s3[now].size()<=2)
									{
										pq.pop();
									}
								}
							}
						}
						else
						{
							s[j.first].erase(j);
							if(s[j.first].size())
							{
								flag[mp[*s[j.first].begin()]]=true;
								int now=s[j.first].begin()->second;
//								s3[now].insert(*s[j.first].begin());
							}
						}
					}
				}
			}
		}
		else
		{
			for(pair<int,int>j:s2[i])
			{
				if(flag[mp[j]])
				{
					s3[i].insert(j);
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		cout<<flag[i];
	}
	cout<<endl;
	return 0;
}
/*
in:
3
1 1
1 6
1 5
out:
110
in:
6
1 1
1 2
2 1
2 2
3 1
3 2
out:
110011
*/