Submission #161706

# Submission time Handle Problem Language Result Execution time Memory
161706 2019-11-03T19:25:39 Z Anai medians (balkan11_medians) C++14
100 / 100
108 ms 12056 KB
#include <bits/stdc++.h>
using namespace std;

const int M = 2e5 + 5;

int f[M];

vector<int> v, ant;
set<int> s;
int n, m;


int main() {
#ifdef HOME
	freopen("medians.in", "r", stdin);
	freopen("medians.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int lst;

	cin >> n;
	v.resize(n);
	for (auto &i: v) {
		cin >> i;
		f[i]+= 1; }
	m = 2 * n - 1;

	for (int i = 1; i <= m; ++i)
		if (!f[i])
			s.insert(i);

	lst = v.back();
	if (!--f[lst])
		s.insert(lst);

	for (int i = n - 2; i >= 0; --i) {
		if (v[i] == lst) {
			auto l = prev(s.lower_bound(v[i]));
			auto r = s.lower_bound(v[i]);
			ant.push_back(*l), ant.push_back(*r);
			s.erase(l);
			s.erase(r); }
		else if (v[i] > lst) {
			auto l = prev(s.upper_bound(v[i]));
			auto r = prev(l);
			ant.push_back(*l), ant.push_back(*r);
			s.erase(l);
			s.erase(r); }
		else {
			auto l = s.lower_bound(v[i]);
			auto r = next(l);
			ant.push_back(*l), ant.push_back(*r);
			s.erase(l);
			s.erase(r); }
		lst = v[i];
		if (--f[v[i]] == 0)
			s.insert(v[i]); }

	ant.push_back(*begin(s));

	reverse(begin(ant), end(ant));
	for (auto i: ant)
		cout << i << ' ';
	cout << endl;

	return 0; }
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 5 ms 760 KB Output is correct
3 Correct 8 ms 1144 KB Output is correct
4 Correct 16 ms 2040 KB Output is correct
5 Correct 32 ms 3832 KB Output is correct
6 Correct 66 ms 7544 KB Output is correct
7 Correct 108 ms 12056 KB Output is correct