Language: C++

#include<bits/stdc++.h>
using namespace std;
#define re register int
#define F(x,y,z) for(re x=y;x<=z;x++)
#define FOR(x,y,z) for(re x=y;x>=z;x--)
typedef long long ll;
#define I inline void
#define IN inline int
#define C(x,y) memset(x,y,sizeof(x))
#define STS system("pause")
template<class D>I read(D &res){
	res=0;register D g=1;register char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')g=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		res=(res<<3)+(res<<1)+(ch^48);
		ch=getchar();
	}
	res*=g;
}
int n,a[202000],val[202000],suf[202000];
int pos[202000][2],mx[2],mn[2][2],le[2][2];
char ans[202000];

struct BIT{
	int t[202000],tg[808000],vl[808000],cnt;
	I ad(int x,int vv)
	{
		for(;x<=n;x+=(x&(-x))){
			tg[++cnt]=x;vl[cnt]=t[x];
			t[x]=max(t[x],vv);
		}
	}
	IN get(int x)
	{
		int re=-1e9;
		for(x=min(x,n);x;x-=(x&(-x))) re=max(re,t[x]);
		return re;
	}
	I reback(int x){for(;cnt>x;t[tg[cnt]]=vl[cnt--]);}

}bit[2];

int main(){
	scanf("%d",&n);
	int i,j,k,x,y,cur=n+1,ptr,nq=0;
    for(i=1;i<=n;++i){
    	scanf("%d",&a[i]);
    	a[i]=n+1-a[i];
    	if(cur>a[i]){
    		cur=a[i];val[i]=2;
    	}else val[i]=1;
    }
    memset(bit[1].t,0x8f,sizeof(bit[1].t));
    for(i=n;i;--i) suf[i]=suf[i+1]+(val[i]==2);
    for(i=n;i>1;--i){
    	 for(j=0;j<2;++j) mx[j]=max(0,bit[j].get(a[i]));
    	 for(j=0;j<2;++j){
    	 	x=mx[j]+val[i];
    	 	bit[x&1].ad(a[i],x);
    	 }
    	 for(j=0;j<2;++j) pos[i][j]=bit[j].cnt;
    }
    mn[0][0]=mn[0][1]=n+1;
    for(i=1;i<=n;++i){
    	nq^=1;
        if(i<n)	for(j=0;j<2;++j) bit[j].reback(pos[i+1][j]);
		for(j=0;j<2;++j){
			for(k=0;k<2;++k) mn[nq][k]=mn[nq^1][k],le[nq][k]=le[nq^1][k];
    		if(a[i]<mn[nq^1][j]){mn[nq][j]=a[i];le[nq][j]=le[nq^1][j]+1;}
    		ptr= i==n?(le[nq][0]==le[nq][1]):0;
    		if(i<n){
    			for(k=0;k<2;++k){
    				x=le[nq][k]-le[nq][k^1]+suf[i+1];
    				if(x>=0 && x<=bit[x&1].get(mn[nq][k^1])){ptr=1;break;}
    			}
    		}
    		if(ptr){ans[i]='0'+j;break;}
    	}
    	if(!ans[i]){printf("-1");return 0;}
    }
    for(i=1;i<=n;++i) putchar(ans[i]);
    return 0;
}

Compiler output:
a.cc: In function 'void read(D&)':
a.cc:12:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 |         res=0;register D g=1;register char ch=getchar();
      |                          ^
a.cc:12:44: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 |         res=0;register D g=1;register char ch=getchar();
      |                                            ^~
a.cc: In member function 'int BIT::get(int)':
a.cc:38:23: error: expected unqualified-id before '=' token
   38 |                 int re=-1e9;
      |                       ^
a.cc:39:49: error: expected unqualified-id before '=' token
   39 |                 for(x=min(x,n);x;x-=(x&(-x))) re=max(re,t[x]);
      |                                                 ^
a.cc:3:12: error: expected primary-expression before 'register'
    3 | #define re register int
      |            ^~~~~~~~
a.cc:40:24: note: in expansion of macro 're'
   40 |                 return re;
      |                        ^~
a.cc:3:12: error: expected ';' before 'register'
    3 | #define re register int
      |            ^~~~~~~~
a.cc:40:24: note: in expansion of macro 're'
   40 |                 return re;
      |                        ^~
a.cc:3:21: error: declaration does not declare anything [-fpermissive]
    3 | #define re register int
      |                     ^~~
a.cc:40:24: note: in expansion of macro 're'
   40 |                 return re;
      |                        ^~