#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define mid (l+r)/2
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 100010
int n, b[MAXN], l, r;
bool pos[2*MAXN];
void upd() {
while(l < r && pos[l]) l++;
while(l < r && pos[r]) r--;
}
int main() {
//ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> b[i];
l = 1, r = 2*n-1, pos[b[1]] = 1;
cout << b[1] << ' ';
for(int i = 2; i <= n; i++) {
upd();
if(b[i] == b[i-1]) {
pos[l] = pos[r] = 1;
cout << l << ' ' << r << ' ';
} else if(b[i] > b[i-1]) {
if(pos[b[i]]) {
cout << r << ' ';
pos[r] = 1;
upd();
cout << r << ' ';
pos[r] = 1;
} else {
pos[b[i]] = pos[r] = 1;
cout << b[i] << ' ' << r << ' ';
}
} else {
if(pos[b[i]]) {
cout << l << ' ';
pos[l] = 1;
upd();
cout << l << ' ';
pos[l] = 1;
} else {
pos[b[i]] = pos[l] = 1;
cout << b[i] << ' ' << l << ' ';
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2600 KB |
Output is correct |
2 |
Correct |
0 ms |
2600 KB |
Output is correct |
3 |
Correct |
0 ms |
2600 KB |
Output is correct |
4 |
Correct |
0 ms |
2600 KB |
Output is correct |
5 |
Correct |
0 ms |
2600 KB |
Output is correct |
6 |
Correct |
0 ms |
2600 KB |
Output is correct |
7 |
Correct |
0 ms |
2600 KB |
Output is correct |
8 |
Correct |
0 ms |
2600 KB |
Output is correct |
9 |
Correct |
0 ms |
2600 KB |
Output is correct |
10 |
Correct |
0 ms |
2600 KB |
Output is correct |
11 |
Correct |
0 ms |
2600 KB |
Output is correct |
12 |
Correct |
0 ms |
2600 KB |
Output is correct |
13 |
Correct |
0 ms |
2600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2600 KB |
Output is correct |
2 |
Correct |
0 ms |
2600 KB |
Output is correct |
3 |
Correct |
3 ms |
2600 KB |
Output is correct |
4 |
Correct |
3 ms |
2600 KB |
Output is correct |
5 |
Correct |
16 ms |
2600 KB |
Output is correct |
6 |
Correct |
33 ms |
2600 KB |
Output is correct |
7 |
Correct |
73 ms |
2600 KB |
Output is correct |