提交时间:2026-04-11 14:31:46
运行 ID: 41154
#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define m_p make_pair #define pb push_back #define eb emplace_back using namespace std; typedef long long ll; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } const int maxn=1e6+10; int n,x[maxn],y[maxn],l[maxn],r[maxn],bel[maxn]; vector<pi>vx[maxn]; pi st[maxn],ed[maxn]; int ans[maxn]; bool check(int k){ if(!ed[y[k]].p1)return 1; if(x[k]<=st[y[k]].p1||x[k]>=ed[y[k]].p1)return 1; return 0; } void op(int id){ int x=::x[id],y=::y[id]; ans[id]=1; if(!st[y].p1){st[y]={x,id};return;} if(!ed[y].p1){ed[y]={x,id};if(st[y]>ed[y])swap(st[y],ed[y]);return;} pi it={x,id}; if(it<st[y])swap(it,st[y]);else if(it>ed[y])swap(it,ed[y]); ans[it.p2]=0; if(l[::x[it.p2]]==bel[it.p2]){ int u=::x[it.p2]; while(l[u]<r[u]){if(check(vx[u][l[u]].p2)){op(vx[u][l[u]].p2);break;}l[u]++;} }else{ int u=::x[it.p2]; while(l[u]<r[u]){if(check(vx[u][r[u]].p2)){op(vx[u][r[u]].p2);break;}r[u]--;} } } void slv(){ n=read(); up(i,1,n)x[i]=read(),y[i]=read(),vx[x[i]].eb(y[i],i); up(i,1,1e6){ sort(vx[i].begin(),vx[i].end()),l[i]=0,r[i]=(int)vx[i].size()-1; up(j,0,(int)vx[i].size()-1)bel[vx[i][j].p2]=j; } up(i,1,1e6)if(vx[i].size()){op(vx[i][l[i]].p2);if(l[i]!=r[i])op(vx[i][r[i]].p2);} up(i,1,n)printf("%d",ans[i]); } int main(){ // freopen("cons.in","r",stdin),freopen("cons.out","w",stdout); slv(); return 0; }