Submission #85819

#TimeUsernameProblemLanguageResultExecution timeMemory
85819igzimedians (balkan11_medians)C++17
100 / 100
99 ms14300 KiB
#include <bits/stdc++.h> #define maxN 100005 using namespace std; int a[2*maxN],b[maxN],n,i; set <int> s; set<int>::iterator it; int main() { std::ios_base::sync_with_stdio(false); cin>>n; for(i=0;i<n;i++) cin>>b[i]; a[0]=b[0]; for(i=0;i<2*n-1;i++) s.insert(i+1); s.erase(a[0]); for(i=1;i<n;i++){ if(b[i]==b[i-1]){ it=s.begin(); a[2*i-1]=*it; s.erase(it); it=s.end(); it--; a[2*i]=*it; s.erase(it); } if(b[i]>b[i-1]){ it=s.lower_bound(b[i]); if(*it==b[i]){ a[2*i-1]=b[i]; s.erase(*it); } else{ it=s.end(); it--; a[2*i-1]=*it; s.erase(it); } it=s.end(); it--; a[2*i]=*it; s.erase(it); } if(b[i]<b[i-1]){ it=s.lower_bound(b[i]); if(*it==b[i]){ a[2*i-1]=b[i]; s.erase(*it); } else{ it=s.begin(); a[2*i-1]=*it; s.erase(it); } it=s.begin(); a[2*i]=*it; s.erase(it); } } for(i=0;i<2*n-1;i++) cout<<a[i]<<" "; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...