#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;
set<ll> st;
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]]++;
for(i=1;i<=n*2-1;i++)
if(b[i]==0)
st.insert(i);
jaw[1]=a[1];
for(i=n-1;i>=1;i--)
{
if(a[i]>a[i+1])
{
j=*st.upper_bound(a[i]);
b[j]=1;
sud[j]=1;
jaw[i*2]=j;
st.erase(j);
j=*st.upper_bound(a[i]);
b[j]=1;
sud[j]=1;
jaw[i*2+1]=j;
st.erase(j);
}
else
if(a[i]<a[i+1])
{
j=*st.lower_bound(a[i]);
b[j]=1;
sud[j]=1;
jaw[i*2]=j;
st.erase(j);
j=*st.lower_bound(a[i]);
b[j]=1;
sud[j]=1;
jaw[i*2+1]=j;
st.erase(j);
}
else
{
j=*st.lower_bound(a[i]);
b[j]=1;
sud[j]=1;
jaw[i*2]=j;
st.erase(j);
j=*st.upper_bound(a[i]);
b[j]=1;
sud[j]=1;
jaw[i*2+1]=j;
st.erase(j);
}
b[a[i]]--;
if(b[a[i]]==0&&sud[a[i]]==0)st.insert(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 |
1 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
384 KB |
Not a permutation |
3 |
Incorrect |
2 ms |
384 KB |
Not a permutation |
4 |
Incorrect |
3 ms |
384 KB |
Not a permutation |
5 |
Incorrect |
2 ms |
256 KB |
Not a permutation |
6 |
Incorrect |
3 ms |
384 KB |
Not a permutation |
7 |
Incorrect |
3 ms |
384 KB |
Not a permutation |
8 |
Incorrect |
3 ms |
380 KB |
Not a permutation |
9 |
Incorrect |
2 ms |
384 KB |
Not a permutation |
10 |
Incorrect |
2 ms |
384 KB |
Not a permutation |
11 |
Incorrect |
2 ms |
384 KB |
Not a permutation |
12 |
Incorrect |
3 ms |
512 KB |
Not a permutation |
13 |
Incorrect |
3 ms |
512 KB |
Not a permutation |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
640 KB |
Not a permutation |
2 |
Incorrect |
5 ms |
896 KB |
Not a permutation |
3 |
Incorrect |
11 ms |
1536 KB |
Not a permutation |
4 |
Incorrect |
17 ms |
2560 KB |
Not a permutation |
5 |
Incorrect |
49 ms |
5280 KB |
Not a permutation |
6 |
Incorrect |
89 ms |
10420 KB |
Not a permutation |
7 |
Incorrect |
137 ms |
15412 KB |
Not a permutation |