/*
Should you keep the light on reason?
I'VE HELD PROMISES UNBROKEN.
written by ღꦿ࿐
*/
int n,a[N],pmx[N] , mxcnt[N] ;
signed main()
{
read(n) ;
rep(i,1,n) read(a[i]) ;
rep(i,1,n) {
mxcnt[i] = mxcnt[i - 1] ;
pmx[i] = max(pmx[i - 1] , a[i]) ;
if(pmx[i] == a[i]) {
mxcnt[i] ++ ;
}
}
seg<Max> s0(n + 2) , s1(n + 2);
auto S = [&] (int x) -> seg<Max>& {
if(x == 0) return s0 ;
return s1 ;
} ;
S(0).update( n + 1 , Max(0) ) ;
Rep(i,n,1) {
int e = 0 , o = 0 , t = 1 + (pmx[i] == a[i]) ;
e = S(((t == 2) ? 0 : 1)).query(a[i] , n + 1).x + t ;
o = S(((t == 2) ? 1 : 0)).query(a[i] , n + 1).x + t ;
S(0).update(a[i] , Max(e));
S(1).update(a[i] , Max(o));
}
auto CheckA = [&] (int cx , int cy , int rem , int x_nw,int y_nw) -> bool {
int ned = rem + cx - cy ;
return ned >= 0 && S(ned & 1).query(y_nw , n + 1).x >= ned ;
} ;
auto CheckB = [&] (int cx , int cy , int rem , int x_nw,int y_nw) -> bool {
int ned = rem + cy - cx ;
return ned >= 0 && S(ned & 1).query(x_nw , n + 1).x >= ned ;
} ;
if(!CheckA(0 , 0 , mxcnt[n] , 0 , 0) && !CheckB(0 , 0 , mxcnt[n] , 0 , 0)) return puts("-1") & 0 ;
string s;
int cx = 0 , cy = 0 , vx = 0 , vy = 0 , rem;
rep(i,1,n) {
for(int c:{0,1}) S(c).update(a[i] , Max( )) ;
rem = mxcnt[n] - mxcnt[i] ;
if ( CheckA(cx + (a[i] > vx), cy , rem , max(a[i] , vx) , vy)
|| CheckB(cx + (a[i] > vx), cy , rem , max(a[i] , vx) , vy) ){
s.push_back('0') ;
cx += (a[i] > vx) && (vx = a[i]) ;
}
else {
s.push_back('1') ;
cy += (a[i] > vy) && (vy = a[i]) ;
}
}
cout << s << '\n' ;
return 0;
}
struct Add {
ll x;
Add(ll v = 0) : x(v) {}
Add& operator*=(Add ot) {
x += ot.x ;
return *this;
}
Add operator+(Add ot) {
return Add(x + ot.x) ;
}
} ;
struct Min {
ll x;
Min(ll v = 2e18) : x(v) {}
operator ll ( ) const {
return x ;
}
bool operator<(Min o1) {
return x < o1.x ;
}
bool operator>(Min o1) {
return x > o1.x ;
}
Min operator+(Min o1) {
return Min(x < o1.x ? x : o1.x);
}
Min& operator+=(Min ot) {
(x > ot.x) && (x = ot.x);
return *this ;
}
Min& operator*=(Add ot) {
x += ot.x ;
return *this ;
}
} ;
struct Max {
ll x;
Max(ll v = -2e18) : x(v) {}
operator int ( ) const {
return x ;
}
bool operator<(Max o1) {
return x < o1.x ;
}
bool operator>(Max o1) {
return x > o1.x ;
}
Max operator+(Max o1) {
return Max(x > o1.x ? x : o1.x);
}
Max& operator+=(Max ot) {
(x < ot.x) && (x = ot.x);
return *this ;
}
Max& operator*=(Add ot) {
x += ot.x ;
return *this ;
}
} ;
struct RangeSum {
ll sum , len ;
RangeSum(ll a=0,ll b=0) : sum(a) , len(b) {}
RangeSum& operator*=(Add ot) {
sum += ot.x * len ;
return *this;
}
RangeSum operator+(RangeSum ot) {
return RangeSum(sum + ot.sum , len + ot.len);
}
} ;
template <typename _Ifo> class seg {
#define ls x<<1
#define rs x<<1|1
#define mid ((l+r)>>1)
private:
const int siz ;
_Ifo *arr ;
void _maintain(int x) {
arr[x] = arr[ls] + arr[rs] ;
}
void _build(int x,int l,int r,_Ifo *base) {
if(l == r) {
arr[x] = base[l] ;
return ;
}
_build(ls , l , mid , base) ; _build(rs , mid + 1 , r , base) ;
_maintain(x);
}
void _build(int x,int l,int r,vector <_Ifo> &base) {
if(l == r) {
arr[x] = base[l - 1] ;
return ;
}
_build(ls , l , mid , base) ; _build(rs , mid + 1 , r , base) ;
_maintain(x);
}
_Ifo _query(int x,int l,int r,int L,int R) {
if(L > R || l > R || L > r) return _Ifo( );
if(L <= l && r <= R) return arr[x] ;
return _query(ls,l,mid,L,R) + _query(rs,mid+1,r,L,R) ;
}
void _update(int x,int l,int r,int &p,_Ifo &e) {
if(l == r) {
arr[x] = e ;
return ;
}
p <= mid ? _update(ls,l,mid,p,e) : _update(rs,mid+1,r,p,e); _maintain(x) ;
}
public:
seg (int S)
: siz (S) {arr = new _Ifo[siz << 2] ( ) ; }
seg (vector<_Ifo> Vec)
: siz (Vec.size( )) {arr = new _Ifo[siz << 2] ( ) ; _build(1,1,siz,Vec); }
seg (int S,_Ifo *base)
: siz (S) {arr = new _Ifo[siz + 2] ( ) ; _build(1,1,siz,base);}
void build(_Ifo *base) {
_build(1,1,siz,base) ;
}
_Ifo query(int l,int r) {
return _query(1,1,siz,l,r) ;
}
void update(int p,_Ifo e) {
_update(1,1,siz,p,e) ;
}
#undef ls
#undef rs
#undef mid
} ;
剪贴板
剪贴板 joacyztn
剪贴板信息
剪贴板信息
- 收录
- 更新