Submission #210769

#TimeUsernameProblemLanguageResultExecution timeMemory
210769Yojahuangmedians (balkan11_medians)C++14
100 / 100
107 ms11048 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; int n; set<int> G; void addmin() { int v = *G.begin(); cout << v << ' '; G.erase(G.find(v)); } void addmax() { int v = *(--G.end()); cout << v << ' '; G.erase(G.find(v)); } int main(){ ios::sync_with_stdio(0),cin.tie(0); int pre, v; while (cin >> n) { G.clear(); for (int i = 1; i <= 2 * n - 1; ++i) { G.insert(i); } cin >> v; cout << v << ' '; pre = v; G.erase(G.find(pre)); for (int i = 1; i < n; ++i) { cin >> v; if (v > pre) { if (G.find(v) == G.end()) { addmax(); }else { G.erase(G.find(v)); cout << v << ' '; } addmax(); }else if(v == pre) { addmin(); addmax(); }else if(v < pre) { if (G.find(v) == G.end()) { addmin(); }else { G.erase(G.find(v)); cout << v << ' '; } addmin(); } pre = v; } cout << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...