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 <bits/stdc++.h>
#define maxN 100005
using namespace std;
int a[2*maxN],b[maxN],n,i;
set <int> s;
set<int>::iterator it;
int main()
{
std::ios_base::sync_with_stdio(false);
cin>>n;
for(i=0;i<n;i++) cin>>b[i];
a[0]=b[0];
for(i=0;i<2*n-1;i++) s.insert(i+1);
s.erase(a[0]);
for(i=1;i<n;i++){
if(b[i]==b[i-1]){
it=s.begin();
a[2*i-1]=*it;
s.erase(it);
it=s.end();
it--;
a[2*i]=*it;
s.erase(it);
}
if(b[i]>b[i-1]){
it=s.lower_bound(b[i]);
if(*it==b[i]){
a[2*i-1]=b[i];
s.erase(*it);
}
else{
it=s.end();
it--;
a[2*i-1]=*it;
s.erase(it);
}
it=s.end();
it--;
a[2*i]=*it;
s.erase(it);
}
if(b[i]<b[i-1]){
it=s.lower_bound(b[i]);
if(*it==b[i]){
a[2*i-1]=b[i];
s.erase(*it);
}
else{
it=s.begin();
a[2*i-1]=*it;
s.erase(it);
}
it=s.begin();
a[2*i]=*it;
s.erase(it);
}
}
for(i=0;i<2*n-1;i++) cout<<a[i]<<" ";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |