#include <bits/stdc++.h>
#ifdef BLAT
#include "debug/debug.hpp"
#else
#define debug(x...)
#endif
using namespace std;
void nextValue(int &last, int coef, const set <int> &myset) {
while (myset.find(last) == myset.end())
last += coef;
}
void insertValue(int value, vector <int> &v, set <int> &myset) {
v.push_back(value);
myset.erase(value);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
vector <int> a, b;
set <int> myset;
cin >> n;
b.resize(n);
cin >> b[0];
a.push_back(b[0]);
for (int i = 1; i < 2 * n; i++)
if (i != b[0])
myset.insert(i);
int l = *myset.begin();
int r = *myset.rbegin();
for (int i = 1; i < n; i++) {
cin >> b[i];
nextValue(l, 1, myset);
nextValue(r, -1, myset);
if (b[i] == b[i - 1]) {
insertValue(l, a, myset);
insertValue(r, a, myset);
} else if (b[i] > b[i - 1]) {
if (myset.find(b[i]) != myset.end()) {
insertValue(b[i], a, myset);
nextValue(r, -1, myset);
insertValue(r, a, myset);
} else {
nextValue(r, -1, myset);
insertValue(r, a, myset);
nextValue(r, -1, myset);
insertValue(r, a, myset);
}
} else {
if (myset.find(b[i]) != myset.end()) {
insertValue(b[i], a, myset);
nextValue(l, 1, myset);
insertValue(l, a, myset);
} else {
nextValue(l, 1, myset);
insertValue(l, a, myset);
nextValue(l, 1, myset);
insertValue(l, a, myset);
}
}
}
for (auto it : a)
cout << it << ' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
4 ms |
724 KB |
Output is correct |
3 |
Correct |
7 ms |
1108 KB |
Output is correct |
4 |
Correct |
14 ms |
2132 KB |
Output is correct |
5 |
Correct |
28 ms |
3924 KB |
Output is correct |
6 |
Correct |
64 ms |
7516 KB |
Output is correct |
7 |
Correct |
110 ms |
11584 KB |
Output is correct |