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;
using ll = long long;
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;
cin>>n;
int b[n];
for(int i = 0; i < n; i++)cin>>b[i];
vector<int>ans;
int mn = 1, mx = 2 * n - 1;
bool used[2 * n]={0};
used[b[0]] = 1;
ans.push_back(b[0]);
auto addMax = [&](){
while(used[mx])mx--;
ans.push_back(mx);
used[mx]=1;
};
auto addMin = [&](){
while(used[mn])mn++;
ans.push_back(mn);
used[mn]=1;
};
for(int i = 1; i < n; i++){
if(b[i] == b[i - 1]){
addMax();
addMin();
}
else if(b[i] > b[i - 1]){
addMax();
if(!used[b[i]]){
ans.push_back(b[i]);
used[b[i]] = 1;
}
else addMax();
}
else{
addMin();
if(!used[b[i]]){
ans.push_back(b[i]);
used[b[i]] = 1;
}
else addMin();
}
}
for(int i : ans)cout<<i<<' ';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |