Submission #1316947

#TimeUsernameProblemLanguageResultExecution timeMemory
1316947dantemedians (balkan11_medians)C++20
5 / 100
16 ms3424 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 3;
int n, ans[N], b[N], vis[N];

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> b[i];
	for (int i = n, pos = 2*n - 1, pre = 0; i >= 1; i--){
		if (b[i] != pre){
			ans[pos] = b[i];
			vis[b[i]] = 1;
			pre = b[i];
		}
		pos -= 2;
	}
	int sm = 1, bg = 0, s = 1, e = 2 * n - 1;
	for (int i = 2; i <= 2*n - 1; i++){
		if (ans[i]) {
			sm++;
		} else{
			if (sm < bg) {
				while (vis[s]) s++;
				vis[s] = 1;
				ans[i] = s;
				sm++;
			} else {
				while (vis[e]) e--;
				vis[e] = 1;
				ans[i] = e;
				bg++;
			}
		}
	}


	for (int i = 1; i <= 2*n - 1; i++) cout << ans[i] << " ";
	cout << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...