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 <iostream>
#include <vector>
using namespace std;
#define upd while(mark[left]) left++; while(mark[right]) right--
int n, b[100005];
bool mark[2 * 100005];
vector<int> ans;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> b[i];
}
mark[0] = mark[2 * n] = 1;
int left = 0, right = 2 * n;
ans.push_back(b[0]);
mark[b[0]] = 1;
for (int i = 1; i < n; i++) {
upd;
if (b[i - 1] < b[i]) {
ans.push_back(right);
mark[right] = 1;
if (mark[b[i]]) {
upd;
ans.push_back(right);
mark[right] = 1;
} else {
ans.push_back(b[i]);
mark[b[i]] = 1;
}
} else if (b[i - 1] > b[i]) {
ans.push_back(left);
mark[left] = 1;
if (mark[b[i]]) {
upd;
ans.push_back(left);
mark[left] = 1;
} else {
ans.push_back(b[i]);
mark[b[i]] = 1;
}
} else {
ans.push_back(left), ans.push_back(right);
mark[left] = mark[right] = 1;
}
}
for (int i : ans) {
cout << i << ' ';
}
cout << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |