Submission #341664

#TimeUsernameProblemLanguageResultExecution timeMemory
341664xiaowuc1medians (balkan11_medians)C++14
100 / 100
130 ms12908 KiB
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <vector> using namespace std; // BEGIN NO SAD #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound typedef vector<int> vi; #define f first #define s second // END NO SAD typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<vector<ll>> matrix; const int SZ = 1 << 18; int tree[2 * SZ]; void upd(int idx) { idx += SZ; while(idx) { tree[idx]++; idx /= 2; } } int qry(int lhs, int rhs) { int ret = 0; lhs += SZ; rhs += SZ; while(lhs <= rhs) { if(lhs%2) ret += tree[lhs++]; if(rhs%2==0) ret += tree[rhs--]; lhs /= 2; rhs /= 2; } return ret; } void solve() { int n; cin >> n; set<int> s; for(int i = 1; i < 2*n; i++) s.insert(i); vector<int> ret; for(int a = 1; a <= n; a++) { int x; cin >> x; if(s.count(x)) { ret.pb(x); upd(ret.back()); s.erase(ret.back()); } while(qry(1, x-1) < a-1) { ret.pb(*s.begin()); upd(ret.back()); s.erase(ret.back()); } while(sz(ret) < 2*a-1) { ret.pb(*s.rbegin()); upd(ret.back()); s.erase(ret.back()); } } for(int i = 0; i < sz(ret); i++) cout << ret[i] << " \n"[i == sz(ret)-1]; } // !editcommand? // are there edge cases (N=1?) // are array sizes proper (scaled by proper constant, for example 2* for koosaga tree) // integer overflow? // DS reset properly between test cases // are you doing geometry in floating points // are you not using modint when you should int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...