답안 #146130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
146130 2019-08-22T09:51:17 Z evpipis Hacker (BOI15_hac) C++11
100 / 100
324 ms 8952 KB
#include <bits/stdc++.h>
using namespace std;

const int len = 5e5+5, inf = 1e9;
int arr[len], out[len], val[4*len], n;

void build(int p, int l, int r){
    val[p] = inf;

    if (l == r)
        return;

    int mid = (l+r)/2;
    build(2*p, l, mid);
    build(2*p+1, mid+1, r);
}

void prop(int p, int l, int r){
    if (val[p] == inf || l == r)
        return;

    val[2*p] = min(val[2*p], val[p]);
    val[2*p+1] = min(val[2*p+1], val[p]);
    val[p] = inf;
}

void upd(int p, int l, int r, int i, int j, int v){
    prop(p, l, r);
    if (r < i || j < l)
        return;
    if (i <= l && r <= j)
        return void(val[p] = min(val[p], v));

    int mid = (l+r)/2;
    upd(2*p, l, mid, i, j, v);
    upd(2*p+1, mid+1, r, i, j, v);
}

int ask(int p, int l, int r){
    prop(p, l, r);
    if (l == r)
        return val[p];

    int mid = (l+r)/2;
    return max(ask(2*p, l, mid), ask(2*p+1, mid+1, r));
}

void change(int i, int j, int v){
    if (i <= j){
        upd(1, 0, n-1, i, j, v);
    }
    else{
        upd(1, 0, n-1, i, n-1, v);
        upd(1, 0, n-1, 0, j, v);
    }
}

int main(){
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &arr[i]);

    build(1, 0, n-1);

    int k = (n+1)/2;
    for (int i = 0, j = 0, sum = 0; i < n; i++){
        while ((n+j-i)%n < k){
            sum += arr[j];
            j = (j+1)%n;
        }

        change(i, (j+n-1)%n, sum);
        sum -= arr[i];
    }

    printf("%d\n", ask(1, 0, n-1));
    return 0;
}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
hac.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &arr[i]);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 252 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 252 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 4 ms 452 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 252 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
31 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 252 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 48 ms 1712 KB Output is correct
5 Correct 120 ms 4088 KB Output is correct
6 Correct 160 ms 4472 KB Output is correct
7 Correct 193 ms 7032 KB Output is correct
8 Correct 324 ms 8628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 252 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 4 ms 452 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 252 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
31 Correct 4 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 252 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 48 ms 1712 KB Output is correct
36 Correct 120 ms 4088 KB Output is correct
37 Correct 160 ms 4472 KB Output is correct
38 Correct 193 ms 7032 KB Output is correct
39 Correct 324 ms 8628 KB Output is correct
40 Correct 7 ms 504 KB Output is correct
41 Correct 13 ms 760 KB Output is correct
42 Correct 18 ms 888 KB Output is correct
43 Correct 124 ms 4108 KB Output is correct
44 Correct 316 ms 8588 KB Output is correct
45 Correct 60 ms 2168 KB Output is correct
46 Correct 186 ms 6904 KB Output is correct
47 Correct 314 ms 8568 KB Output is correct
48 Correct 315 ms 8952 KB Output is correct
49 Correct 304 ms 7932 KB Output is correct
50 Correct 304 ms 8092 KB Output is correct