# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
660786 | 600Mihnea | medians (balkan11_medians) | C++17 | 84 ms | 12748 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
bool home = 0;
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 7;
int n;
int b[N];
int a[N];
set<int> s;
int nxt_up(int i)
{
auto it = s.lower_bound(i);
assert(it != s.end());
int sol = *it;
s.erase(it);
return sol;
}
int nxt_down(int i)
{
auto it = s.lower_bound(i + 1);
assert(it != s.begin());
it--;
int sol = *it;
s.erase(it);
return sol;
}
int main()
{
if (home == 0)
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
else
{
freopen ("input.txt", "r", stdin);
}
cin >> n;
for (int i = 1; i <= 2 * n - 1; i++)
{
s.insert(i);
}
for (int i = 1; i <= n; i++)
{
cin >> b[i];
}
a[1] = nxt_up(b[1]);
for (int i = 2; i <= n; i++)
{
if (b[i] == b[i - 1])
{
a[2 * i - 2] = nxt_up(1);
a[2 * i - 1] = nxt_down(2 * n - 1);
continue;
}
if (b[i] < b[i - 1])
{
if (s.count(b[i]))
{
a[2 * i - 2] = nxt_up(b[i]);
a[2 * i - 1] = nxt_up(1);
}
else
{
a[2 * i - 2] = nxt_up(1);
a[2 * i - 1] = nxt_up(1);
}
continue;
}
if (b[i] > b[i - 1])
{
if (s.count(b[i]))
{
a[2 * i - 2] = nxt_down(b[i]);
a[2 * i - 1] = nxt_down(2 * n - 1);
}
else
{
a[2 * i - 2] = nxt_down(2 * n - 1);
a[2 * i - 1] = nxt_down(2 * n - 1);
}
continue;
}
assert(0);
}
for (int i = 1; i <= 2 * n - 1; i++)
{
cout << a[i] << " ";
}
cout << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |