Submission #343920

# Submission time Handle Problem Language Result Execution time Memory
343920 2021-01-04T18:10:53 Z flappybird medians (balkan11_medians) C++14
90 / 100
300 ms 17720 KB
#include <bits/stdc++.h>
using namespace std;
#define MAX 602020
int l[MAX], r[MAX];
int tree[MAX];
int arr[MAX];
int s;
vector<int>ans;
set<int>S;
void init(int x = 1) {
	if (x >= s) {
		l[x] = r[x] = x - s + 1;
		return;
	}
	init(x * 2);
	init(x * 2 + 1);
	l[x] = l[x * 2];
	r[x] = r[x * 2 + 1];
}
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 sumquery(int low, int high, int loc = 1) {
	if (l[loc] == low && r[loc] == high) return tree[loc];
	else if (r[loc * 2] >= high) return sumquery(low, high, loc * 2);
	else if (l[loc * 2 + 1] <= low) return sumquery(low, high, loc * 2 + 1);
	else return sumquery(low, r[loc * 2], loc * 2) + sumquery(l[loc * 2 + 1], 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;
	s = 1 << (int)ceil(log2(2 * N - 1));
	int i;
	for (i = 1; i <= 2 * N - 1; i++) S.insert(i);
	init();
	int a;
	cin >> a;
	update(a);
	for (i = 1; i <= N - 1; i++) {
		cin >> a;
		if (arr[a] == 0) {
			update(a);
			if (sumquery(1, a) < sumquery(a, 2 * N - 1)) {
				update(minn());
			}
			else {
				update(maxn());
			}
		}
		else {
			int r1, r2;
			r1 = sumquery(1, a);
			r2 = sumquery(a, 2 * N - 1);
			if (r1 < r2) {
				update(minn());
				update(minn());
			}
			else if (r1 > r2) {
				update(maxn());
				update(maxn());
			}
			else {
				update(minn());
				update(maxn());
			}
		}
	}
	for (auto i : ans) cout << i << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 4 ms 492 KB Output is correct
13 Correct 6 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 620 KB Output is correct
2 Correct 25 ms 1004 KB Output is correct
3 Correct 44 ms 1644 KB Output is correct
4 Correct 92 ms 3052 KB Output is correct
5 Correct 184 ms 5484 KB Output is correct
6 Execution timed out 373 ms 10732 KB Time limit exceeded
7 Execution timed out 582 ms 17720 KB Time limit exceeded