답안 #161705

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161705 2019-11-03T19:24:42 Z Anai 중앙값 배열 (balkan11_medians) C++14
90 / 100
40 ms 11128 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;

int f[N];

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; }
# 결과 실행 시간 메모리 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 428 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 5 ms 760 KB Output is correct
3 Correct 8 ms 1272 KB Output is correct
4 Correct 17 ms 2012 KB Output is correct
5 Correct 31 ms 3832 KB Output is correct
6 Runtime error 40 ms 11128 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 3 ms 1400 KB Execution killed with signal 11 (could be triggered by violating memory limits)