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<iostream>
#include<map>
using namespace::std;
int r,l;
map<int,bool> m;
void gf(){
while(m.count(l)) ++l;
cout<<l<<' ';
m[l++]=1;
}
void gl(){
while(m.count(r)) --r;
cout<<r<<' ';
m[r--]=1;
}
int main(){
int n;
cin>>n;
r=2*n-1;
l=1;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
cout<<a[0]<<' ';
m[a[0]]=1;
for(int i=1;i<n;i++){
if(m.count(a[i])){
if(a[i-1]>a[i]) gf(),gf();
if(a[i-1]<a[i]) gl(),gl();
else gf(),gl();
}else{
m[a[i]]=1;
cout<<a[i]<<' ';
if(a[i-1]>a[i]) gf();
else gl();
}
}
cout<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |