답안 #72187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72187 2018-08-26T05:50:51 Z 우리는 진실을 잊고 살잖아~~~(#2195, leejseo, king114) 박스런 (FXCUP3_box) C++11
100 / 100
405 ms 9516 KB
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAX_N 500000

int N;
int H[MAX_N];
int tree[MAX_N*4];
int ans[MAX_N];

int init(int left, int right, int node)
{
    if(left == right) return tree[node] = H[left];
    int mid = (left + right)/2;
    return tree[node] = max(init(left, mid, node*2), init(mid+1, right, node*2+1));
}

int max_range(int left, int right, int node, int start, int end)
{
    if(start <= left && right <= end) return tree[node];
    if(right < start || left > end) return 0;
    int mid = (left+right)/2;
    return max(max_range(left, mid, node*2, start, end), \
               max_range(mid+1, right, node*2+1, start, end));
}

int main()
{
    //freopen("input.txt","r",stdin);
    scanf("%d", &N);
    for(int i=0;i<N;++i) scanf("%d", &H[i]);
    init(0, N-1, 1);

    int w = 1, p = 0;
    while(w<=N && p<N){
        if(p-w>=0 && max_range(0, N-1, 1, p-w, p-1) < H[p]){
            printf("%d ", p-w+1);
            w++;
        }else p++;
    }
    while(w++<=N) printf("%d ", -1);
    return 0;
}

Compilation message

box.cpp: In function 'int main()':
box.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
box.cpp:31:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=0;i<N;++i) scanf("%d", &H[i]);
                          ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 524 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 2 ms 524 KB Output is correct
6 Correct 2 ms 524 KB Output is correct
7 Correct 2 ms 524 KB Output is correct
8 Correct 2 ms 524 KB Output is correct
9 Correct 3 ms 576 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 2 ms 576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 524 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 2 ms 524 KB Output is correct
6 Correct 2 ms 524 KB Output is correct
7 Correct 2 ms 524 KB Output is correct
8 Correct 2 ms 524 KB Output is correct
9 Correct 3 ms 576 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 2 ms 576 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 6 ms 620 KB Output is correct
14 Correct 38 ms 1404 KB Output is correct
15 Correct 63 ms 2240 KB Output is correct
16 Correct 78 ms 2444 KB Output is correct
17 Correct 276 ms 5164 KB Output is correct
18 Correct 278 ms 7836 KB Output is correct
19 Correct 359 ms 8768 KB Output is correct
20 Correct 405 ms 9516 KB Output is correct
21 Correct 394 ms 9516 KB Output is correct