#include <stdio.h>
const int MAXN = 2e5 + 5;
int vis[MAXN], minimum, maximum, A[MAXN], B[MAXN], N;
void plus(){ while(vis[minimum]) minimum++; }
void minus(){ while(vis[maximum]) maximum--; }
int main(){
scanf("%d", &N);
for(int i=1; i<=N; ++i) scanf("%d", &B[i]);
minimum = 0, maximum = 2 * N;
vis[minimum] = vis[maximum] = vis[B[1]] = 1, A[1] = B[1];
for(int i=2; i<=N; ++i){
if(B[i - 1] == B[i]){
plus(); A[2 * i - 2] = minimum, vis[minimum] = 1;
minus(); A[2 * i - 1] = maximum, vis[maximum] = 1;
}
else if(B[i - 1] < B[i]){
if(!vis[B[i]]){
A[2 * i - 2] = B[i], vis[B[i]] = 1;
minus(); A[2 * i - 1] = maximum, vis[maximum] = 1;
}
else{
minus(); A[2 * i - 2] = maximum, vis[maximum] = 1;
minus(); A[2 * i - 1] = maximum, vis[maximum] = 1;
}
}
else if(B[i - 1] > B[i]){
if(!vis[B[i]]){
A[2 * i - 2] = B[i], vis[B[i]] = 1;
plus(); A[2 * i - 1] = minimum, vis[minimum] = 1;
}
else{
plus(); A[2 * i - 2] = minimum, vis[minimum] = 1;
plus(); A[2 * i - 1] = minimum, vis[minimum] = 1;
}
}
}
for(int i=1; i<2*N; ++i) printf("%d ", A[i]);
puts("");
return 0;
}
Compilation message
medians.cpp: In function 'int main()':
medians.cpp:11:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
~~~~~^~~~~~~~~~
medians.cpp:12:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1; i<=N; ++i) scanf("%d", &B[i]);
~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
488 KB |
Output is correct |
5 |
Correct |
2 ms |
488 KB |
Output is correct |
6 |
Correct |
2 ms |
488 KB |
Output is correct |
7 |
Correct |
2 ms |
488 KB |
Output is correct |
8 |
Correct |
2 ms |
488 KB |
Output is correct |
9 |
Correct |
2 ms |
488 KB |
Output is correct |
10 |
Correct |
2 ms |
552 KB |
Output is correct |
11 |
Correct |
2 ms |
552 KB |
Output is correct |
12 |
Correct |
2 ms |
568 KB |
Output is correct |
13 |
Correct |
2 ms |
568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
604 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
4 ms |
732 KB |
Output is correct |
4 |
Correct |
8 ms |
1036 KB |
Output is correct |
5 |
Correct |
12 ms |
1576 KB |
Output is correct |
6 |
Correct |
27 ms |
2548 KB |
Output is correct |
7 |
Correct |
38 ms |
3740 KB |
Output is correct |