# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
340118 | MilosMilutinovic | medians (balkan11_medians) | C++14 | 38 ms | 2540 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=100050;
int n,a[N],ans[N],mn,mx;
bool was[2*N];
int down(){
while(was[mx])--mx;
was[mx]=1;
return mx;
}
int up(){
while(was[mn])++mn;
was[mn]=1;
return mn;
}
int main(){
scanf("%i",&n);
for(int i=1;i<=n;i++)scanf("%i",&a[i]);
ans[1]=a[1];
was[a[1]]=1;
mn=0,mx=2*n;
was[0]=1,was[2*n]=1;
for(int i=2;i<=n;i++){
if(a[i]==a[i-1]){
ans[2*i-2]=down();
ans[2*i-1]=up();
}else{
if(a[i]>a[i-1]){
if(was[a[i]]){
ans[2*i-2]=down();
ans[2*i-1]=down();
}else{
ans[2*i-2]=a[i];
was[a[i]]=1;
ans[2*i-1]=down();
}
}else{
if(was[a[i]]){
ans[2*i-2]=up();
ans[2*i-1]=up();
}else{
ans[2*i-2]=a[i];
was[a[i]]=1;
ans[2*i-1]=up();
}
}
}
}
for(int i=1;i<=2*n-1;i++)printf("%i ",ans[i]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |