답안 #26657

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26657 2017-07-04T13:18:18 Z top34051 중앙값 배열 (balkan11_medians) C++14
100 / 100
69 ms 2996 KB
#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);
        }
    }
}

Compilation message

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);
                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2996 KB Output is correct
2 Correct 0 ms 2996 KB Output is correct
3 Correct 0 ms 2996 KB Output is correct
4 Correct 0 ms 2996 KB Output is correct
5 Correct 0 ms 2996 KB Output is correct
6 Correct 0 ms 2996 KB Output is correct
7 Correct 0 ms 2996 KB Output is correct
8 Correct 0 ms 2996 KB Output is correct
9 Correct 0 ms 2996 KB Output is correct
10 Correct 0 ms 2996 KB Output is correct
11 Correct 0 ms 2996 KB Output is correct
12 Correct 0 ms 2996 KB Output is correct
13 Correct 0 ms 2996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2996 KB Output is correct
2 Correct 0 ms 2996 KB Output is correct
3 Correct 3 ms 2996 KB Output is correct
4 Correct 6 ms 2996 KB Output is correct
5 Correct 19 ms 2996 KB Output is correct
6 Correct 29 ms 2996 KB Output is correct
7 Correct 69 ms 2996 KB Output is correct