This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pii pair<long double, int>
using namespace std;
int N;
bool vis[200005];
int A[200005];
int mn, mx;
int p;
void addmn() {
while(vis[mn] == 1) mn++;
vis[mn] = 1;
A[++p] = mn;
}
void addmx() {
while(vis[mx] == 1) mx--;
vis[mx] = 1;
A[++p] = mx;
}
int main() {
ios_base::sync_with_stdio(0);
cin >> N;
cin >> A[1];
int bef = A[1], now;
vis[A[1]] = 1;
mn = 1, mx = N * 2 - 1;
p = 1;
for(int i = 2; i <= N; i++) {
cin >> now;
if(now > bef) {
if(vis[now]) {
addmx();
addmx();
}else {
vis[now] = 1;
A[++p] = now;
addmx();
}
}else if(now < bef) {
if(vis[now]) {
addmn();
addmn();
}else {
vis[now] = 1;
A[++p] = now;
addmn();
}
}else {
addmx();
addmn();
}
bef = now;
}
for(int i = 1; i <= p; i++) {
cout << A[i] << " ";
}
cin >> N;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |