Submission #637883

#TimeUsernameProblemLanguageResultExecution timeMemory
637883googlemedians (balkan11_medians)C++17
100 / 100
72 ms12356 KiB
#include<bits/stdc++.h> using namespace std; int main(){ cin.tie(0)->sync_with_stdio(0); int n,l,r,cur,la; cin >> n; l = 1,r = n*2-1; vector<int> ans; set<int> used; cin >> cur; used.insert(cur); ans.push_back(cur); for (int i = 0;i<n-1;i++) { la = cur; cin >> cur; if (used.count(cur)){ if (cur == la){ while (used.count(l)) l++; used.insert(l); ans.push_back(l); l++; while (used.count(r)) r--; used.insert(r); ans.push_back(r); r--; } else{ if (cur > la){ while (used.count(r)) r--; used.insert(r); ans.push_back(r); r--; while (used.count(r)) r--; used.insert(r); ans.push_back(r); r--; } else{ while (used.count(l)) l++; used.insert(l); ans.push_back(l); l++; while (used.count(l)) l++; used.insert(l); ans.push_back(l); l++; } } } else{ ans.push_back(cur); used.insert(cur); if (cur > la){ while (used.count(r)) r--; used.insert(r); ans.push_back(r); r--; } else{ while (used.count(l)) l++; used.insert(l); ans.push_back(l); l++; } } } for (auto a:ans) cout << a << ' '; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...