제출 #27494

#제출 시각아이디문제언어결과실행 시간메모리
27494TAMREF중앙값 배열 (balkan11_medians)C++11
100 / 100
136 ms11784 KiB
#include <bits/stdc++.h>
using namespace std;
const int mx=100005;
int B[mx];
int N;
set<int> L;
void input(){
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d",&B[i]);
    }
    for(int i=0;i<2*N-1;i++) L.insert(i+1);
}
void solve(){
    printf("%d ",B[0]); L.erase(B[0]);
    for(int i=1;i<N;i++){
        if(B[i]==B[i-1]){
            printf("%d ",*L.begin()); L.erase(*L.begin());
            printf("%d ",*L.rbegin()); L.erase(*L.rbegin());
        }
        else if(B[i]<B[i-1]){
            if(L.find(B[i])==L.end()){
                printf("%d ",*L.begin()); L.erase(*L.begin());
                printf("%d ",*L.begin()); L.erase(*L.begin());
            }else{
                printf("%d ",B[i]); L.erase(B[i]);
                printf("%d ",*L.begin()); L.erase(*L.begin());
            }
        }
        else{
            if(L.find(B[i])==L.end()){
                printf("%d ",*L.rbegin()); L.erase(*L.rbegin());
                printf("%d ",*L.rbegin()); L.erase(*L.rbegin());
            }else{
                printf("%d ",B[i]); L.erase(B[i]);
                printf("%d ",*L.rbegin()); L.erase(*L.rbegin());
            }
        }
    }
}
int main(){
    input();
    solve();
    return 0&puts("");
}

컴파일 시 표준 에러 (stderr) 메시지

medians.cpp: In function 'void input()':
medians.cpp:8:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&N);
                   ^
medians.cpp:10:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&B[i]);
                          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...