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 pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
using namespace std;
ll n,i,a[202020],b[202020],sud[202020],jaw[202020],j;
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n;
for(i=1;i<=n;i++)cin>>a[i];
for(i=1;i<n;i++)b[a[i]]++;
jaw[1]=a[1];
for(i=n-1;i>=1;i--)
{
if(a[i]>a[i+1])
{
for(j=a[i];j>=1;j--)
if(b[j]==0&&sud[j]==0)
{
b[j]=1;
sud[j]=1;
jaw[i*2]=j;
break;
}
for(j=a[i];j>=1;j--)
if(b[j]==0&&sud[j]==0)
{
b[j]=1;
sud[j]=1;
jaw[i*2+1]=j;
break;
}
}
else
if(a[i]<a[i+1])
{
for(j=a[i];j<=n*2-1;j++)
if(b[j]==0&&sud[j]==0)
{
b[j]=1;
sud[j]=1;
jaw[i*2]=j;
break;
}
for(j=a[i];j<=n*2-1;j++)
if(b[j]==0&&sud[j]==0)
{
b[j]=1;
sud[j]=1;
jaw[i*2+1]=j;
break;
}
}
else
{
for(j=a[i];j>=1;j--)
if(b[j]==0&&sud[j]==0)
{
b[j]=1;
sud[j]=1;
jaw[i*2]=j;
break;
}
for(j=a[i];j<=n*2-1;j++)
if(b[j]==0&&sud[j]==0)
{
b[j]=1;
sud[j]=1;
jaw[i*2+1]=j;
break;
}
}
b[a[i]]--;
}
for(i=1;i<=(n*2-1);i++)
if(i<(n*2-1))
cout<<jaw[i]<<" ";
else
cout<<jaw[i]<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |