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<vector>
using namespace std;
bool visi[200002];
int A[200002];
int B[100001];
int main()
{
ios_base::sync_with_stdio(false);
int n;
cin>>n;
int maxi=2*n-1;
int mini=1;
for(int i=1;i<=n;i++)
{
cin>>B[i];
}
visi[B[1]]=true;
A[1]=B[1];
for(int i=2;i<=n;i++)
{
if(B[i]==B[i-1])
{
while(visi[maxi])
maxi--;
while(visi[mini])
mini++;
visi[maxi]=true;
visi[mini]=true;
A[2*i-2]=maxi;
A[2*i-1]=mini;
}
else if(B[i]>B[i-1])
{
if(!visi[B[i]])
{
A[2*i-2]=B[i];
while(visi[maxi])
maxi--;
visi[maxi]=true;
A[2*i-1]=maxi;
}
else
{
while(visi[maxi])
maxi--;
visi[maxi]=true;
A[2*i-2]=maxi;
while(visi[maxi])
maxi--;
visi[maxi]=true;
A[2*i-1]=maxi;
}
}
else if(B[i]<B[i-1])
{
if(!visi[B[i]])
{
A[2*i-2]=B[i];
while(visi[mini])
mini++;
visi[mini]=true;
A[2*i-1]=mini;
}
else
{
while(visi[mini])
mini++;
visi[mini]=true;
A[2*i-2]=mini;
while(visi[mini])
mini++;
visi[mini]=true;
A[2*i-1]=mini;
}
}
}
for(int i=1;i<=2*n-1;i++)
{
if(i!=1)
cout<<" ";
cout<<A[i];
}
cout<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |