# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29205 | Nirjhor | medians (balkan11_medians) | C++14 | 33 ms | 3604 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.
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
bitset <N> vis;
int n, a[N], b[N], l, r;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", b + i);
}
a[1] = b[1];
l = 0, r = n + n;
vis[b[1]] = vis[l] = vis[r] = 1;
for (int i = 2, j = 2; i <= n; ++i, j += 2) {
if (b[i] == b[i - 1]) {
while (vis[l]) ++l;
while (vis[r]) --r;
a[j] = l, a[j + 1] = r;
vis[l] = vis[r] = 1;
}
if (b[i] < b[i - 1]) {
if (vis[b[i]]) {
while (vis[l]) ++l;
a[j] = l, vis[l] = 1;
while (vis[l]) ++l;
a[j + 1] = l, vis[l] = 1;
} else {
a[j] = b[i], vis[b[i]] = 1;
while (vis[l]) ++l;
a[j + 1] = l, vis[l] = 1;
}
}
if (b[i] > b[i - 1]) {
if (vis[b[i]]) {
while (vis[r]) --r;
a[j] = r, vis[r] = 1;
while (vis[r]) --r;
a[j + 1] = r, vis[r] = 1;
} else {
a[j] = b[i], vis[b[i]] = 1;
while (vis[r]) --r;
a[j + 1] = r, vis[r] = 1;
}
}
}
for (int i = 1; i < n + n; ++i) {
printf("%d ", a[i]);
}
puts("");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |