# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
60491 | junodeveloper | medians (balkan11_medians) | C++17 | 65 ms | 3244 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>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
int n, b[100010], a[200010], c1,c2;
bool chk[200010];
int getc1() { while(c1 <=2*n-1 && chk[c1]) c1++; return c1; }
int getc2() { while(c2 && chk[c2]) c2--; return c2; }
int main() {
scanf("%d", &n);
c1 = 1, c2 = 2*n-1;
for(int i=1; i<=n; i++) {
scanf("%d", b+i);
if(i == 1) {
chk[a[1] = b[i]] = 1;
continue;
}
if(b[i-1] > b[i]) {
if(!chk[b[i]]) chk[a[2*(i-1)] = b[i]] = chk[a[2*(i-1)+1] = getc1()] = 1;
else chk[a[2*(i-1)] = getc1()] = chk[a[2*(i-1)+1] = getc1()] = 1;
} else if(b[i-1] < b[i]) {
if(!chk[b[i]]) chk[a[2*(i-1)] = b[i]] = chk[a[2*(i-1)+1] = getc2()] = 1;
else chk[a[2*(i-1)] = getc2()] = chk[a[2*(i-1)+1] = getc2()] = 1;
} else chk[a[2*(i-1)] = getc1()] = chk[a[2*(i-1)+1] = getc2()] = 1;
}
for(int i=1; i<2*n; i++) printf("%d ", a[i]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |