답안 #1119851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1119851 2024-11-27T13:58:20 Z PagodePaiva Hacker (BOI15_hac) C++17
100 / 100
169 ms 43188 KB
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 500010;
const int LOGN = 20;
int pref[2*N];
int n;
int v[2*N];
int val[2*N];

struct Segtree{
    int tree[8*N];
    int join(int a, int b){
        return max(a, b);
    }
    void build(int node, int l, int r){
        if(l == r){
            tree[node] = val[l];
            return;
        }
        int mid = (l+r)/2;
        build(2*node, l, mid);
        build(2*node+1, mid+1, r);
        tree[node] = join(tree[2*node], tree[2*node+1]);
        return;
    }
    int query(int node, int l, int r, int tl, int tr){
        if(l > tr or tl > r) return 0;
        if(l <= tl and tr <= r) return tree[node];
        int mid =(tl+tr)/2;
        return join(query(2*node, l, r, tl, mid), query(2*node+1, l, r, mid+1, tr));
    }
} seg;

int query(int l, int r){
    if(l > r) r += n;
    return pref[r]-pref[l-1];
}

int32_t main(){
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> v[i];
        v[n+i] = v[i];
    }
    for(int i = 1;i <= 2*n;i++){
        pref[i] = pref[i-1]+v[i];
    }
    //int res = 0;
    int d = n/2;
    int sum = 0;
    for(int i = 1;i <= d;i++){
        sum += v[i];
    }
    for(int i = 1;i+d-1 <= 2*n;i++){
        val[i] = sum;
        if(i+d > 2*n) break;
        sum -= v[i];
        sum += v[i+d];
    }
    seg.build(1, 1, 2*n);
    int res = 0;
    for(int i = 1;i <= n;i++){
        int l = i, r = i+n;
        int tot = pref[r]-pref[l]-seg.query(1, l+1,r-d, 1, 2*n);
        res = max(res, tot);
    }
    cout << res  << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4448 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 1 ms 4436 KB Output is correct
4 Correct 1 ms 4692 KB Output is correct
5 Correct 1 ms 4436 KB Output is correct
6 Correct 1 ms 4604 KB Output is correct
7 Correct 1 ms 4436 KB Output is correct
8 Correct 1 ms 4436 KB Output is correct
9 Correct 1 ms 4436 KB Output is correct
10 Correct 2 ms 4560 KB Output is correct
11 Correct 1 ms 4436 KB Output is correct
12 Correct 1 ms 4436 KB Output is correct
13 Correct 1 ms 4436 KB Output is correct
14 Correct 1 ms 4436 KB Output is correct
15 Correct 1 ms 4436 KB Output is correct
16 Correct 1 ms 4436 KB Output is correct
17 Correct 1 ms 4436 KB Output is correct
18 Correct 1 ms 4436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4448 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 1 ms 4436 KB Output is correct
4 Correct 1 ms 4692 KB Output is correct
5 Correct 1 ms 4436 KB Output is correct
6 Correct 1 ms 4604 KB Output is correct
7 Correct 1 ms 4436 KB Output is correct
8 Correct 1 ms 4436 KB Output is correct
9 Correct 1 ms 4436 KB Output is correct
10 Correct 2 ms 4560 KB Output is correct
11 Correct 1 ms 4436 KB Output is correct
12 Correct 1 ms 4436 KB Output is correct
13 Correct 1 ms 4436 KB Output is correct
14 Correct 1 ms 4436 KB Output is correct
15 Correct 1 ms 4436 KB Output is correct
16 Correct 1 ms 4436 KB Output is correct
17 Correct 1 ms 4436 KB Output is correct
18 Correct 1 ms 4436 KB Output is correct
19 Correct 1 ms 4600 KB Output is correct
20 Correct 1 ms 4436 KB Output is correct
21 Correct 1 ms 4436 KB Output is correct
22 Correct 2 ms 6740 KB Output is correct
23 Correct 3 ms 8788 KB Output is correct
24 Correct 2 ms 6740 KB Output is correct
25 Correct 3 ms 8788 KB Output is correct
26 Correct 4 ms 8788 KB Output is correct
27 Correct 1 ms 4436 KB Output is correct
28 Correct 1 ms 4436 KB Output is correct
29 Correct 1 ms 4436 KB Output is correct
30 Correct 3 ms 8788 KB Output is correct
31 Correct 4 ms 8788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4436 KB Output is correct
2 Correct 1 ms 4436 KB Output is correct
3 Correct 3 ms 8788 KB Output is correct
4 Correct 23 ms 13504 KB Output is correct
5 Correct 54 ms 24300 KB Output is correct
6 Correct 98 ms 24652 KB Output is correct
7 Correct 99 ms 37196 KB Output is correct
8 Correct 154 ms 42828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4448 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 1 ms 4436 KB Output is correct
4 Correct 1 ms 4692 KB Output is correct
5 Correct 1 ms 4436 KB Output is correct
6 Correct 1 ms 4604 KB Output is correct
7 Correct 1 ms 4436 KB Output is correct
8 Correct 1 ms 4436 KB Output is correct
9 Correct 1 ms 4436 KB Output is correct
10 Correct 2 ms 4560 KB Output is correct
11 Correct 1 ms 4436 KB Output is correct
12 Correct 1 ms 4436 KB Output is correct
13 Correct 1 ms 4436 KB Output is correct
14 Correct 1 ms 4436 KB Output is correct
15 Correct 1 ms 4436 KB Output is correct
16 Correct 1 ms 4436 KB Output is correct
17 Correct 1 ms 4436 KB Output is correct
18 Correct 1 ms 4436 KB Output is correct
19 Correct 1 ms 4600 KB Output is correct
20 Correct 1 ms 4436 KB Output is correct
21 Correct 1 ms 4436 KB Output is correct
22 Correct 2 ms 6740 KB Output is correct
23 Correct 3 ms 8788 KB Output is correct
24 Correct 2 ms 6740 KB Output is correct
25 Correct 3 ms 8788 KB Output is correct
26 Correct 4 ms 8788 KB Output is correct
27 Correct 1 ms 4436 KB Output is correct
28 Correct 1 ms 4436 KB Output is correct
29 Correct 1 ms 4436 KB Output is correct
30 Correct 3 ms 8788 KB Output is correct
31 Correct 4 ms 8788 KB Output is correct
32 Correct 1 ms 4436 KB Output is correct
33 Correct 1 ms 4436 KB Output is correct
34 Correct 3 ms 8788 KB Output is correct
35 Correct 23 ms 13504 KB Output is correct
36 Correct 54 ms 24300 KB Output is correct
37 Correct 98 ms 24652 KB Output is correct
38 Correct 99 ms 37196 KB Output is correct
39 Correct 154 ms 42828 KB Output is correct
40 Correct 5 ms 8952 KB Output is correct
41 Correct 10 ms 9044 KB Output is correct
42 Correct 11 ms 11524 KB Output is correct
43 Correct 66 ms 24360 KB Output is correct
44 Correct 162 ms 42828 KB Output is correct
45 Correct 32 ms 13652 KB Output is correct
46 Correct 85 ms 37168 KB Output is correct
47 Correct 152 ms 42804 KB Output is correct
48 Correct 169 ms 43188 KB Output is correct
49 Correct 158 ms 42300 KB Output is correct
50 Correct 140 ms 42428 KB Output is correct