#include <bits/stdc++.h>
using ll = long long;
int const nmax = 100000;
int a[1 + nmax], b[1 + 2 * nmax];
bool fr[1 + nmax];
std::set<int> s;
int main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
int n;
std::cin >> n;
for(int i = 1;i <= n; i++) {
std::cin >> a[i];
}
for(int i = 1;i < 2 * n; i++)
s.insert(i);
b[1] = a[1];
fr[a[1]] = 1;
s.erase(a[1]);
for(int i = 2;i <= n; i++) {
if(a[i - 1] < a[i]) {
auto it = s.end();
it--;
b[2 * i - 1] = *it;
s.erase(b[2 * i - 1]);
if(fr[a[i]]) {
it = s.end();
it--;
b[2 * i - 2] = *it;
} else {
b[2 * i - 2] = a[i];
}
s.erase(b[2 * i - 2]);
fr[b[2 * i - 1]] = true;
fr[b[2 * i - 2]] = true;
} else if(a[i] == a[i - 1]) {
auto it = s.end();
it--;
b[2 * i - 1] = *s.begin();
b[2 * i - 2] = *it;
s.erase(b[2 * i - 1]);
s.erase(b[2 * i - 2]);
fr[b[2 * i - 1]] = true;
fr[b[2 * i - 2]] = true;
} else {
auto it = s.begin();
b[2 * i - 1] = *it;
it++;
if(fr[a[i]])
b[2 * i - 2] = *it;
else
b[2 * i - 2] = a[i];
s.erase(b[2 * i - 1]);
s.erase(b[2 * i - 2]);
fr[b[2 * i - 1]] = 1;
fr[b[2 * i - 2]] = 1;
}
}
for(int i = 1;i < 2 * n; i++)
std::cout << b[i] << " ";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
224 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
3 ms |
724 KB |
Output is correct |
3 |
Correct |
6 ms |
1236 KB |
Output is correct |
4 |
Correct |
12 ms |
2176 KB |
Output is correct |
5 |
Correct |
24 ms |
4052 KB |
Output is correct |
6 |
Incorrect |
50 ms |
8020 KB |
Integer 16843009 violates the range [1, 127999] |
7 |
Incorrect |
80 ms |
12316 KB |
Integer 16843009 violates the range [1, 199999] |