제출 #26657

#제출 시각아이디문제언어결과실행 시간메모리
26657top34051중앙값 배열 (balkan11_medians)C++14
100 / 100
69 ms2996 KiB
#include<bits/stdc++.h>
using namespace std;
int n;
bool ok[200005];
int tree[200005];
void add(int x,int val) {
    while(x<=2*n-1) {
        tree[x] += val;
        x += x&-x;
    }
}
int sum(int x) {
    int ans = 0;
    while(x) {
        ans += tree[x];
        x -= x&-x;
    }
    return ans;
}
main() {
    int i,j,x,sz;
    scanf("%d",&n);
    i = 1; j = 2*n-1;
    for(sz=1;sz<=2*n-1;sz+=2) {
        scanf("%d",&x);
        if(!ok[x]) {
            ok[x] = 1;
            add(x,1);
            printf("%d ",x);
        }
        while(sum(x-1)<sz/2) {
            while(ok[i]) i++;
            ok[i] = 1;
            add(i,1);
            printf("%d ",i);
        }
        while(sum(2*n-1)-sum(x)<sz/2) {
            while(ok[j]) j--;
            ok[j] = 1;
            add(j,1);
            printf("%d ",j);
        }
    }
}

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

medians.cpp:20:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
medians.cpp: In function 'int main()':
medians.cpp:22:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
medians.cpp:25:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&x);
                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...