/*input
5
1 3 3 4 5
*/
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
ios_base::sync_with_stdio(false);
int n;
cin >> n;
int m[n];
for (int i = 0; i < n; i++)
cin >> m[i];
set<int>nebus;
for (int i = 1; i <= 2 * n - 1; i++)
nebus.insert(i);
for (int i = 0; i < n; i++)
nebus.erase(m[i]);
deque<int>answer;
for (int i = n - 1; i > 0; i--)
{
if (m[i] == m[i - 1])
{
auto it = nebus.upper_bound(m[i]);
assert(it != nebus.end());
answer.push_front(*it);
nebus.erase(it);
it = nebus.lower_bound(m[i]);
assert(it != nebus.begin());
it--;
answer.push_front(*it);
nebus.erase(it);
}
else
{
nebus.insert(m[i]);
if (m[i] > m[i - 1])
{
auto it = nebus.lower_bound(m[i]);
assert(it != nebus.end());
answer.push_front(*it);
nebus.erase(it);
it = nebus.lower_bound(m[i]);
assert(it != nebus.end());
answer.push_front(*it);
nebus.erase(it);
}
else
{
auto it = nebus.upper_bound(m[i]);
assert(it != nebus.begin());
it--;
answer.push_front(*it);
nebus.erase(it);
it = nebus.upper_bound(m[i]);
assert(it != nebus.begin());
it--;
answer.push_front(*it);
nebus.erase(it);
}
}
}
answer.push_front(m[0]);
for (int i : answer)
cout << i << " ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Not a permutation |
2 |
Incorrect |
2 ms |
384 KB |
Not a permutation |
3 |
Incorrect |
2 ms |
384 KB |
Not a permutation |
4 |
Incorrect |
2 ms |
384 KB |
Not a permutation |
5 |
Incorrect |
2 ms |
384 KB |
Not a permutation |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Incorrect |
2 ms |
384 KB |
Not a permutation |
8 |
Incorrect |
2 ms |
384 KB |
Not a permutation |
9 |
Incorrect |
2 ms |
384 KB |
Not a permutation |
10 |
Incorrect |
2 ms |
384 KB |
Not a permutation |
11 |
Incorrect |
3 ms |
356 KB |
Not a permutation |
12 |
Incorrect |
3 ms |
384 KB |
Not a permutation |
13 |
Incorrect |
2 ms |
512 KB |
Not a permutation |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
512 KB |
Not a permutation |
2 |
Incorrect |
4 ms |
768 KB |
Not a permutation |
3 |
Incorrect |
8 ms |
1280 KB |
Not a permutation |
4 |
Incorrect |
15 ms |
2048 KB |
Not a permutation |
5 |
Incorrect |
30 ms |
3960 KB |
Not a permutation |
6 |
Incorrect |
61 ms |
7388 KB |
Not a permutation |
7 |
Incorrect |
110 ms |
11456 KB |
Not a permutation |