#include <bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define len(x) (int)x.size()
#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int gen(int l, int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll gen(ll l, ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
template<typename T, typename H>
ostream& operator<<(ostream& os, const pair<T, H> &p){
return os << '(' << p.st << ", " << p.nd << ')';
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T> &vec){
os << '{';
for(int i = 0; i < len(vec); i++){
if(i != 0) os << ", ";
os << vec[i];
}
os << '}';
return os;
}
const int N = 100'007;
int n;
int t[N];
bool blocked[N*2];
bool used[N*2];
void next_left(int &left){
while(used[left] || blocked[left]) left++;
}
void next_right(int &right){
while(used[right] || blocked[right]) right--;
}
void solve(){
cin >> n;
for(int i = 0; i < n; i++) cin >> t[i];
cout << t[0] << ' ';
used[t[0]] = true;
int left = 1;
int right = n*2 - 1;
for(int i = 1; i < n; i++){
if(t[i] < t[i-1]){
cout << t[i] << ' ';
used[t[i]] = true;
next_left(left);
cout << left << ' ';
used[left] = true;
left++;
}else if(t[i] > t[i-1]){
cout << t[i] << ' ';
used[t[i]] = true;
next_right(right);
cout << right << ' ';
used[right] = true;
right--;
}else{
next_left(left);
cout << left << ' ';
used[left] = true;
left++;
next_right(right);
cout << right << ' ';
used[right] = true;
right--;
}
}
cout << '\n';
}
int32_t main(){
fastio();
int tt = 1;
// cin >> tt;
while(tt--) solve();
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |