Submission #147627

#TimeUsernameProblemLanguageResultExecution timeMemory
147627zubecmedians (balkan11_medians)C++14
100 / 100
112 ms9848 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int n, b[100100]; set<int> q; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin >> n; for (int i = 1; i <= 2*n-1; i++) q.insert(i); vector <int> ans; for (int i = 1; i <= n; i++){ cin >> b[i]; if (i == 1){ q.erase(b[i]); ans.push_back(b[i]); continue; } if (b[i] == b[i-1]){ ans.push_back(*q.begin()); q.erase(q.begin()); ans.push_back(*prev(q.end())); q.erase(prev(q.end())); } else if (b[i] < b[i-1]){ if (q.find(b[i]) != q.end()){ ans.push_back(b[i]); q.erase(b[i]); ans.push_back(*q.begin()); q.erase(q.begin()); } else { ans.push_back(*q.begin()); q.erase(q.begin()); ans.push_back(*q.begin()); q.erase(q.begin()); } } else { if (q.find(b[i]) != q.end()){ ans.push_back(b[i]); q.erase(b[i]); ans.push_back(*prev(q.end())); q.erase(prev(q.end())); } else { ans.push_back(*prev(q.end())); q.erase(prev(q.end())); ans.push_back(*prev(q.end())); q.erase(prev(q.end())); } } } for (int i : ans) cout << i << ' '; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...