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;
typedef long long ll;
typedef long double ld;
int n, b[100100];
set<int> q;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin >> n;
for (int i = 1; i <= 2*n-1; i++)
q.insert(i);
vector <int> ans;
for (int i = 1; i <= n; i++){
cin >> b[i];
if (i == 1){
q.erase(b[i]);
ans.push_back(b[i]);
continue;
}
if (b[i] == b[i-1]){
ans.push_back(*q.begin());
q.erase(q.begin());
ans.push_back(*prev(q.end()));
q.erase(prev(q.end()));
}
else if (b[i] < b[i-1]){
if (q.find(b[i]) != q.end()){
ans.push_back(b[i]);
q.erase(b[i]);
ans.push_back(*q.begin());
q.erase(q.begin());
} else {
ans.push_back(*q.begin());
q.erase(q.begin());
ans.push_back(*q.begin());
q.erase(q.begin());
}
}
else {
if (q.find(b[i]) != q.end()){
ans.push_back(b[i]);
q.erase(b[i]);
ans.push_back(*prev(q.end()));
q.erase(prev(q.end()));
} else {
ans.push_back(*prev(q.end()));
q.erase(prev(q.end()));
ans.push_back(*prev(q.end()));
q.erase(prev(q.end()));
}
}
}
for (int i : ans)
cout << i << ' ';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |