Submission #343931

#TimeUsernameProblemLanguageResultExecution timeMemory
343931flappybirdmedians (balkan11_medians)C++14
90 / 100
761 ms13640 KiB
#include <bits/stdc++.h> using namespace std; #define MAX 302020 int l[MAX], r[MAX]; int tree[MAX]; int arr[MAX]; int s, d; vector<int>ans; set<int>S; void update(int loc) { ans.push_back(loc); arr[loc] = 1; S.erase(loc); loc += s - 1; while (loc > 0) { tree[loc]++; loc /= 2; } } int lg(int x) { int cnt = 0; while (x) { x /= 2; cnt++; } return cnt - 1; } int sumquery(int low, int high, int loc = 1) { int l, r; int ll, rr; int res = lg(loc); int a = d - res; l = (loc - (1 << res)) << a; r = l + (1 << a) - 1; rr = (l + r) / 2; ll = rr + 1; l++; r++; ll++; rr++; if (l == low && r == high) return tree[loc]; else if (rr >= high) return sumquery(low, high, loc * 2); else if (ll <= low) return sumquery(low, high, loc * 2 + 1); else return sumquery(low, rr, loc * 2) + sumquery(ll, high, loc * 2 + 1); } int minn() { return *S.begin(); } int maxn() { set<int>::iterator it; it = S.end(); it--; return *it; } int main(void) { int N; cin >> N; d = (int)ceil(log2(2 * N - 1)); s = 1 << d; int i; for (i = 1; i <= 2 * N - 1; i++) S.insert(i); int a; cin >> a; update(a); for (i = 1; i <= N - 1; i++) { cin >> a; if (arr[a] == 0) update(a); while (sumquery(1, a) < (i + 1)) update(minn()); while (sumquery(a, 2 * N - 1) < (i + 1)) update(maxn()); } for (auto i : ans) cout << i << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...