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 F first
#define S second
#define pii pair<int, int>
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 2e5 + 10;
set<int> st;
int a[N], b[N];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
for(int i=1; i<2*n; i++)
st.insert(i);
for(int i=0; i<n; i++){
cin >> a[i];
if(i == 0){
b[i] = a[i];
st.erase(a[i]);
}
else{
if(st.find(a[i]) != st.end()){
if(a[i] > a[i - 1]){
b[2*i] = a[i];
st.erase(a[i]);
b[2*i - 1] = *(st.rbegin());
st.erase(*st.rbegin());
}else if(a[i] < a[i - 1]){
b[2*i] = a[i];
st.erase(a[i]);
b[2*i - 1] = *(st.begin());
st.erase(st.begin());
}
}
else{
if(a[i] == a[i - 1]){
b[2*i] = *st.begin();
st.erase(st.begin());
b[2*i - 1] = *(st.rbegin());
st.erase(*st.rbegin());
}else if(a[i] < a[i - 1]){
b[2*i] = *st.begin();
st.erase(st.begin());
b[2*i - 1] = *st.begin();
st.erase(st.begin());
}else{
b[2*i] = *st.rbegin();
st.erase(*st.rbegin());
b[2*i - 1] = *st.rbegin();
st.erase(*st.rbegin());
}
}
}
}
for(int i=0; i<2*n - 1; i++)
cout << b[i] << ' '; cout << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |