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>
using namespace std;
const int N = 2e5 + 5;
int n, a[N];
int L, R;
map < int, bool > used;
inline void Left(){
while(used.find(L) != used.end()){
L += 1;
}
cout << L << " ";
used[L] = true;
L += 1;
}
inline void Right(){
while(used.find(R) != used.end()){
R -= 1;
}
cout << R << " ";
used[R] = true;
R -= 1;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
L = 1;
R = 2 * n - 1;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
cout << a[1] << " ";
used[a[1]] = true;
for(int i = 2; i <= n; i++){
if(used.find(a[i]) != used.end()){
if(a[i - 1] > a[i]){
Left();
Left();
}
else if(a[i - 1] < a[i]){
Right();
Right();
}
else{
assert(false);
}
}
else{
used[a[i]] = true;
cout << a[i] << " ";
if(a[i - 1] > a[i]){
Left();
}
else if(a[i - 1] < a[i]){
Right();
}
else{
assert(false);
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |