#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{
Left();
Right();
}
}
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 |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
768 KB |
Output is correct |
2 |
Correct |
6 ms |
768 KB |
Output is correct |
3 |
Correct |
9 ms |
1280 KB |
Output is correct |
4 |
Correct |
17 ms |
2176 KB |
Output is correct |
5 |
Correct |
35 ms |
4116 KB |
Output is correct |
6 |
Correct |
64 ms |
7668 KB |
Output is correct |
7 |
Correct |
96 ms |
12024 KB |
Output is correct |