Submission #632763

#TimeUsernameProblemLanguageResultExecution timeMemory
632763MasterTastermedians (balkan11_medians)C++14
100 / 100
103 ms12964 KiB
#include <iostream> #include <vector> #include <set> #define ll long long #define MAXN 200010 #define pb push_back #define pii pair<int, int> #define xx first #define yy second using namespace std; int n, b[MAXN], a[MAXN]; bool bio[MAXN]; int main() { cin>>n; for (int i=1; i<=n; i++) cin>>b[i]; a[1]=b[1]; bio[a[1]]=true; set<int> s; for (int i=1; i<=2*n-1; i++) if (i!=a[1]) s.insert(i); for (int i=2; i<=n; i++) { if (b[i]>b[i-1]) { if (!bio[b[i]]) { a[2*i-2]=b[i]; bio[b[i]]=true; s.erase(b[i]); } else { int x=*(s.rbegin()); a[2*i-2]=x; bio[x]=true; s.erase(x); } int x=*(s.rbegin()); a[2*i-1]=x; bio[x]=true; s.erase(x); } else if (b[i]<b[i-1]) { if (!bio[b[i]]) { a[2*i-2]=b[i]; bio[b[i]]=true; s.erase(b[i]); } else { int x=*(s.begin()); a[2*i-2]=x; bio[x]=true; s.erase(x); } int x=*(s.begin()); a[2*i-1]=x; bio[x]=true; s.erase(x); } else { int x=*(s.begin()); a[2*i-2]=x; bio[x]=true; s.erase(x); x=*(s.rbegin()); a[2*i-1]=x; bio[x]=true; s.erase(x); } } for (int i=1; i<=2*n-1; i++) cout<<a[i]<<" "; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...