#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int n, a[100002], b[200002], viz[200002];
set<int>s;
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
viz[a[1]] = 1;
for (int i = 1; i < 2 * n; i++)
s.insert(i);
s.erase(a[1]);
for (int i = 2; i <= n; i++) {
if (a[i] == a[i - 1]) {
b[2 * i - 1] = *s.begin();
b[2 * i - 2] = *s.rbegin();
assert(viz[b[2 * i - 1]] == 0 and viz[b[2 * i - 2]] == 0);
s.erase(b[2 * i - 1]);
s.erase(b[2 * i - 2]);
viz[b[2 * i - 2]] = 1;
viz[b[2 * i - 1]] = 1;
}
else if (a[i] > a[i - 1]) {
b[2 * i - 1] = *s.rbegin();
auto it = s.rbegin();
if (viz[a[i]]) {
it--;
b[2 * i - 2] = *it;
}
else
b[2 * i - 2] = a[i];
assert(viz[b[2 * i - 1]] == 0 and viz[b[2 * i - 2]] == 0);
s.erase(b[2 * i - 1]);
s.erase(b[2 * i - 2]);
viz[b[2 * i - 2]] = 1;
viz[b[2 * i - 1]] = 1;
}
else {
b[2 * i - 1] = *s.begin();
auto it = s.begin();
if (viz[a[i]]) {
it++;
b[2 * i - 2] = *it;
}
else
b[2 * i - 2] = a[i];
assert(viz[b[2 * i - 1]] == 0 and viz[b[2 * i - 2]] == 0);
s.erase(b[2 * i - 1]);
s.erase(b[2 * i - 2]);
viz[b[2 * i - 2]] = 1;
viz[b[2 * i - 1]] = 1;
}
}
b[1] = a[1];
for (int i = 1; i < 2 * n; i++)
cout << b[i] << " ";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 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 |
6 ms |
1236 KB |
Output is correct |
4 |
Runtime error |
11 ms |
4108 KB |
Execution killed with signal 6 |
5 |
Correct |
24 ms |
4280 KB |
Output is correct |
6 |
Correct |
49 ms |
8264 KB |
Output is correct |
7 |
Correct |
84 ms |
12876 KB |
Output is correct |