This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*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])
{
answer.push_front(*nebus.begin());
nebus.erase(nebus.begin());
answer.push_front(*(--nebus.end()));
nebus.erase(--nebus.end());
}
else
{
nebus.insert(m[i]);
if (m[i] > m[i - 1])
{
answer.push_front(*(--nebus.end()));
nebus.erase(--nebus.end());
answer.push_front(*(--nebus.end()));
nebus.erase(--nebus.end());
}
else
{
answer.push_front(*nebus.begin());
nebus.erase(nebus.begin());
answer.push_front(*nebus.begin());
nebus.erase(nebus.begin());
}
}
}
answer.push_front(m[0]);
for (int i : answer)
cout << i << " ";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |