#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
int b[100001];
set<int> s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, curr;
cin >> n;
FOR(i, 1, n + 1) {
cin >> b[i];
s.insert(2 * i - 1);
s.insert(2 * i);
}
s.erase(2 * n);
cout << b[1] << ' ';
s.erase(b[1]);
FOR(i, 2, n + 1) {
if (b[i] == b[i - 1]) {
cout << *s.begin() << ' ';
s.erase(*s.begin());
cout << *s.rbegin() << ' ';
s.erase(*s.rbegin());
} else if (b[i] > b[i - 1]) {
if (s.find(b[i]) == s.end()) {
cout << *s.rbegin() << ' ';
s.erase(*s.rbegin());
cout << *s.rbegin() << ' ';
s.erase(*s.rbegin());
} else {
cout << b[i] << ' ';
s.erase(b[i]);
cout << *s.rbegin() << ' ';
s.erase(*s.rbegin());
}
} else {
if (s.find(b[i]) == s.end()) {
cout << *s.begin() << ' ';
s.erase(*s.begin());
cout << *s.begin() << ' ';
s.erase(*s.begin());
} else {
cout << b[i] << ' ';
s.erase(b[i]);
cout << *s.begin() << ' ';
s.erase(*s.begin());
}
}
}
return 0;
}
Compilation message
medians.cpp: In function 'int main()':
medians.cpp:12:12: warning: unused variable 'curr' [-Wunused-variable]
int n, curr;
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
424 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
808 KB |
Output is correct |
3 |
Correct |
8 ms |
1144 KB |
Output is correct |
4 |
Correct |
18 ms |
2216 KB |
Output is correct |
5 |
Correct |
35 ms |
3832 KB |
Output is correct |
6 |
Correct |
78 ms |
7376 KB |
Output is correct |
7 |
Correct |
127 ms |
11528 KB |
Output is correct |