#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e5+7;
int T[LIM], odw[LIM], czy[LIM];
set<int>S;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n;
cin >> n;
rep(i, 2*n-1) S.insert(i+1);
rep(i, n) {
cin >> T[i];
if(!odw[T[i]]) {
czy[T[i]]=1;
odw[T[i]]=1;
S.erase(T[i]);
}
}
vector<int>ans;
for(int i=n-1; i>0; --i) {
if(T[i]==T[i-1]) {
auto it=S.lower_bound(T[i]);
auto a=*it;
ans.pb(a);
--it;
auto b=*it;
ans.pb(b);
S.erase(a);
S.erase(b);
} else if(T[i]<T[i-1]) {
auto it=S.lower_bound(T[i]);
--it;
auto a=*it;
if(czy[i]) a=T[i];
else --it;
auto b=*it;
ans.pb(a);
ans.pb(b);
if(!czy[i]) S.erase(a);
S.erase(b);
} else {
auto it=S.lower_bound(T[i]);
auto a=*it;
if(czy[i]) a=T[i];
else ++it;
auto b=*it;
ans.pb(a);
ans.pb(b);
if(a!=b) S.erase(a);
S.erase(b);
}
}
ans.pb(T[0]);
reverse(all(ans));
for(auto i : ans) cout << i << " ";
cout << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Not a permutation |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
3 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
4 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 11 |
5 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
6 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
7 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
8 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
9 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
10 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
11 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
12 |
Execution timed out |
1089 ms |
348 KB |
Time limit exceeded |
13 |
Incorrect |
1 ms |
344 KB |
Not a permutation |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Not a permutation |
2 |
Runtime error |
2 ms |
1372 KB |
Execution killed with signal 11 |
3 |
Execution timed out |
1095 ms |
1276 KB |
Time limit exceeded |
4 |
Runtime error |
13 ms |
4084 KB |
Execution killed with signal 11 |
5 |
Execution timed out |
1050 ms |
3648 KB |
Time limit exceeded |
6 |
Runtime error |
43 ms |
14420 KB |
Execution killed with signal 11 |
7 |
Runtime error |
65 ms |
21212 KB |
Execution killed with signal 11 |