#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
struct Z {
int i,x,y;
};
int n, b[100010], a[200010], p[100010][2], sz[100010];
bool chk[200010];
vector<Z> V1,V2;
int main() {
scanf("%d", &n);
for(int i=1; i<=n; i++) {
scanf("%d", b+i);
if(i == 1) chk[b[i]] = 1;
else {
if(b[i] == b[i-1]) {
V1.push_back({i,b[i-1],1});
V2.push_back({i,b[i-1],1});
}
else if(b[i] > b[i-1]) V2.push_back({i,b[i-1],2});
else V1.push_back({i,b[i-1],2});
}
}
sort(ALL(V1), [&](const Z& a, const Z& b) {
return a.x < b.x;
});
sort(ALL(V2), [&](const Z& a, const Z& b) {
return a.x > b.x;
});
int c1 = 1, c2 = 2*n-1;
for(auto& it : V1) {
for(int j=0; j<it.y; j++) {
while(chk[c1]) c1++;
chk[c1] = 1, p[it.i][sz[it.i]++] = c1;
}
}
for(auto& it : V2) {
for(int j=0; j<it.y; j++) {
while(chk[c2]) c2--;
chk[c2] = 1, p[it.i][sz[it.i]++] = c2;
}
}
a[1] = b[1];
for(int i=2; i<=n; i++) {
a[2*(i-1)] = p[i][0];
a[2*(i-1)+1] = p[i][1];
}
for(int i=1; i<2*n; i++) printf("%d ", a[i]);
return 0;
}
Compilation message
medians.cpp: In function 'int main()':
medians.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
medians.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", b+i);
~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
576 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
576 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
632 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
764 KB |
Output isn't correct |
6 |
Correct |
3 ms |
764 KB |
Output is correct |
7 |
Incorrect |
3 ms |
764 KB |
Output isn't correct |
8 |
Incorrect |
3 ms |
764 KB |
Output isn't correct |
9 |
Incorrect |
4 ms |
796 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
796 KB |
Output isn't correct |
11 |
Incorrect |
4 ms |
892 KB |
Output isn't correct |
12 |
Incorrect |
3 ms |
892 KB |
Output isn't correct |
13 |
Incorrect |
4 ms |
892 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1136 KB |
Output isn't correct |
2 |
Incorrect |
5 ms |
1288 KB |
Output isn't correct |
3 |
Incorrect |
11 ms |
1624 KB |
Output isn't correct |
4 |
Incorrect |
18 ms |
2228 KB |
Output isn't correct |
5 |
Incorrect |
29 ms |
3276 KB |
Output isn't correct |
6 |
Incorrect |
40 ms |
5472 KB |
Output isn't correct |
7 |
Incorrect |
94 ms |
7928 KB |
Output isn't correct |