이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |