#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;
cin>>n;
int b[n];
for(int i = 0; i < n; i++)cin>>b[i];
vector<int>ans;
int mn = 1, mx = 2 * n - 1;
bool used[2 * n]={0};
used[b[0]] = 1;
ans.push_back(b[0]);
auto addMax = [&](){
while(used[mx])mx--;
ans.push_back(mx);
used[mx]=1;
};
auto addMin = [&](){
while(used[mn])mn++;
ans.push_back(mn);
used[mn]=1;
};
for(int i = 1; i < n; i++){
if(b[i] == b[i - 1]){
addMax();
addMin();
}
else if(b[i] > b[i - 1]){
addMax();
if(!used[b[i]]){
ans.push_back(b[i]);
used[b[i]] = 1;
}
else addMax();
}
else{
addMin();
if(!used[b[i]]){
ans.push_back(b[i]);
used[b[i]] = 1;
}
else addMin();
}
}
for(int i : ans)cout<<i<<' ';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
284 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
3 ms |
860 KB |
Output is correct |
5 |
Correct |
6 ms |
1404 KB |
Output is correct |
6 |
Correct |
12 ms |
2388 KB |
Output is correct |
7 |
Correct |
19 ms |
3788 KB |
Output is correct |