Submission #204517

#TimeUsernameProblemLanguageResultExecution timeMemory
204517alexandra_udristoiumedians (balkan11_medians)C++14
100 / 100
71 ms4216 KiB
#include<iostream> #define DIM 200005 using namespace std; int n, i, p, u; int v[DIM], ff[DIM], sol[DIM]; int main(){ cin>> n; for(i = 1; i <= n; i++){ cin>> v[i]; } sol[1] = v[1]; ff[ v[1] ] = 1; p = 1; u = 2 * n - 1; for(i = 2; i <= n; i++){ while(ff[p] == 1){ p++; } while(ff[u] == 1){ u--; } if(v[i] == v[i - 1]){ sol[2 * i - 2] = p; sol[2 * i - 1] = u; ff[p] = ff[u] = 1; } else{ if(ff[ v[i] ] == 0){ sol[2 * i - 2] = v[i]; ff[ v[i] ] = 1; if(v[i] > v[i - 1]){ sol[2 * i - 1] = u; ff[u] = 1; } else{ sol[2 * i - 1] = p; ff[p] = 1; } } else{ if(v[i] > v[i - 1]){ sol[2 * i - 2] = u; ff[u] = 1; while(ff[u] == 1){ u--; } sol[2 * i - 1] = u; ff[u] = 1; } else{ sol[2 * i - 2] = p; ff[p] = 1; while(ff[p] == 1){ p++; } sol[2 * i - 1] = p; ff[p] = 1; } } } } for(i = 1; i <= 2 * n - 1; i++){ cout<< sol[i] <<" "; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...