This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
#include<set>
using namespace std;
struct pa {
int ix, ep;
bool operator< (const pa& c) const {
return ep<c.ep;
}
}im;
int n, ba[600060], ix2[300030], cnt, fl;
int ncn[300030], par[300030];
bool chk[300030], pbit[300030], xo;
set<pa> sets;
set<pa>::iterator it;
int root(int ix){
while(par[ix]!=-1)xo^=pbit[ix], ix=par[ix];
return ix;
}
void con(int a, int b){
xo=1;
a=root(a), b=root(b);
if(a==b && xo)fl=1;
if(a!=b){
if(ncn[a]>=ncn[b])par[b]=a, ncn[a]+=ncn[b], pbit[b]=xo;
else par[a]=b, ncn[b]+=ncn[a], pbit[a]=xo;
}
}
int main(){
int i, j;
scanf("%d", &n);
for(i=0; i<2*n; i++){
scanf("%d", &ba[i]);
ix2[ba[i]]=i;
}
for(i=1; i<=n; i++)ncn[i]=1, par[i]=-1;
for(i=0; i<2*n; i++){
im.ep=ix2[ba[i]], im.ix=ba[i];
if(im.ep==i)sets.erase(im);
else{
for(it=sets.begin(); it!=sets.end(); it++){
if((*it).ep > im.ep)break;
con(ba[i], (*it).ix);
cnt++;
if(cnt>=n || fl){
puts("IMPOSSIBLE");
return 0;
}
}
sets.insert(im);
}
}
for(i=1; i<=n; i++){
xo=0, root(i);
chk[i]=xo;
}
for(i=0; i<2*n; i++)printf("%c", chk[ba[i]]?'v':'^');
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |