Submission #94679

#TimeUsernameProblemLanguageResultExecution timeMemory
94679Rouge_Hugomedians (balkan11_medians)C++14
0 / 100
57 ms4332 KiB
#include <bits/stdc++.h> using namespace std; vector<int>vv; int a[100009*2+2]; int v[100009*2+2]; int get (int x) { while (v[x]==1) { x--; } return x; } int get1 (int x) { while (v[x]==1) { x++; } return x; } int main() { int l=1; int n;cin>>n; int r=(2*n)-1; for(int i=1;i<=n;i++) { cin>>a[i]; if (i==1) { v[a[i]]=1; vv.push_back(a[i]); continue; } if (v[a[i]]==1) { if (a[i]>a[i-1]) { r=get (r); v[r]=1; vv.push_back(r); r=get (r); v[r]=1; vv.push_back(r); } else { l=get1 (l); v[l]=1; vv.push_back(l); l=get1 (l); v[l]=1; vv.push_back(l); } } else { if (a[i]>a[i-1]) { v[a[i]]=1; r=get (r); v[r]=1; vv.push_back(a[i]); vv.push_back(r); } else { v[a[i]]=1; v[l]=1; l=get1 (l); vv.push_back(a[i]); vv.push_back(l); } } } for(auto pp:vv)cout<<pp<<" "; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...