제출 #1030533

#제출 시각아이디문제언어결과실행 시간메모리
1030533racsosabe중앙값 배열 (balkan11_medians)C++14
0 / 100
19 ms2908 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 2 * 100000 + 5;

int n;
int a[N];
int b[N];
bool vis[N];

void solve() {
	a[1] = b[1]; vis[1] = true;
	int L = 2, R = 2 * n - 1;
	for(int i = 2; i <= n; i++) {
		int l = 2 * i - 2;
		int r = 2 * i - 1;
		if(b[i - 1] == b[i]) {
			while(vis[L]) L += 1;
			a[l] = L; vis[L] = true;
			while(vis[R]) R -= 1;
			a[r] = R; vis[R] = true;
		}
		else if(b[i - 1] > b[i]) {
			if(not vis[b[i]]) {
				while(vis[L]) L += 1;
				a[l] = L; vis[L] = true;
				a[r] = b[i]; vis[b[i]] = true;
			}
			else {
				while(vis[L]) L += 1;
				a[l] = L; vis[L] = true;
				while(vis[L]) L += 1;
				a[R] = L; vis[L] = true;
			}
		}
		else {
			if(not vis[b[i]]) {
				while(vis[R]) R -= 1;
				a[l] = R; vis[R] = true;
				a[r] = b[i]; vis[b[i]] = true;
			}
			else {
				while(vis[R]) R -= 1;
				a[l] = R; vis[R] = true;
				while(vis[R]) R -= 1;
				a[r] = R; vis[R] = true;
			}
		}
	}
}

int main() {
	cin.tie(0) -> sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> b[i];
	solve();
	for(int i = 1; i <= 2 * n - 1; i++) cout << a[i] << " \n"[i == 2 * n - 1];
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...