Submission #737510

#TimeUsernameProblemLanguageResultExecution timeMemory
737510josanneo22medians (balkan11_medians)C++17
100 / 100
28 ms3528 KiB
#include <bits/stdc++.h> #ifdef BLAT #include "debug/debug.hpp" #else #define debug(x...) #endif using namespace std; void nextValue(int &last, int coef, const vector <bool> &visited) { while (visited[last] == true) last += coef; } void insertValue(int value, int &l, int &r, vector <int> &v, vector <bool> &visited) { v.push_back(value); visited[value] = true; nextValue(l, 1, visited); nextValue(r, -1, visited); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector <int> a, b(n); vector <bool> visited(2 * n); cin >> b[0]; a.push_back(b[0]); visited[b[0]] = true; int l = 1, r = 2 * n - 1; for (int i = 1; i < n; i++) { cin >> b[i]; nextValue(l, 1, visited); nextValue(r, -1, visited); if (b[i] == b[i - 1]) { insertValue(l, l, r, a, visited); insertValue(r, l, r, a, visited); } else if (b[i] > b[i - 1]) { if (visited[b[i]] == false) { insertValue(b[i], l, r, a, visited); insertValue(r, l, r, a, visited); } else { insertValue(r, l, r, a, visited); insertValue(r, l, r, a, visited); } } else { if (visited[b[i]] == false) { insertValue(b[i], l, r, a, visited); insertValue(l, l, r, a, visited); } else { insertValue(l, l, r, a, visited); insertValue(l, l, r, a, visited); } } } for (auto it : a) cout << it << ' '; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...