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>
using namespace std;
const int maxn = 200100;
int a[2*maxn], b[maxn], n;
int minvalue, maxvalue;
bool visited[2*maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++) {
cin>>b[i];
}
minvalue = 1;
maxvalue = 2*n-1;
visited[b[1]]=true;
a[1] = b[1];
while(visited[minvalue]) minvalue++;
while(visited[maxvalue]) maxvalue--;
for(int i=2;i<=n;i++) {
if(b[i] == b[i-1]) {
a[2*(i-1)] = minvalue;
visited[minvalue] = true;
while(visited[minvalue]) minvalue++;
a[2*(i-1)+1] = maxvalue;
visited[maxvalue] = true;
while(visited[maxvalue]) maxvalue--;
}
else if(b[i] < b[i-1]) {
if(visited[b[i]]) {
a[2*(i-1)] = minvalue;
visited[minvalue] = true;
while(visited[minvalue]) minvalue++;
a[2*(i-1)+1] = minvalue;
visited[minvalue] = true;
while(visited[minvalue]) minvalue++;
}
else {
a[2*(i-1)] = b[i];
visited[b[i]] = true;
while(visited[minvalue]) minvalue++;
while(visited[maxvalue]) maxvalue--;
a[2*(i-1)+1] = minvalue;
visited[minvalue] = true;
while(visited[minvalue]) minvalue++;
}
}
else if(b[i] > b[i-1]) {
if(visited[b[i]]) {
a[2*(i-1)] = maxvalue;
visited[maxvalue] = true;
while(visited[maxvalue]) maxvalue--;
a[2*(i-1)+1] = maxvalue;
visited[maxvalue] = true;
while(visited[maxvalue]) maxvalue--;
}
else {
a[2*(i-1)] = b[i];
visited[b[i]] = true;
while(visited[maxvalue]) maxvalue--;
while(visited[minvalue]) minvalue++;
a[2*(i-1)+1] = maxvalue;
visited[maxvalue] = true;
while(visited[maxvalue]) maxvalue--;
}
}
}
for(int i=1;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... |