답안 #402842

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
402842 2021-05-12T12:23:00 Z gevacrt Hacker (BOI15_hac) C++17
100 / 100
411 ms 22340 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()

template<class T, void UPDATE(T&, T), T MERGE(T, T)>
struct SEGMENT_TREE {
    int range_l, range_r;
    vector<T> V, lazy; T DEF;

    SEGMENT_TREE(int l, int r, T def = T{}){
        DEF = def;
        V.resize(4*(r-l+1), DEF);
        lazy.resize(4*(r-l+1), DEF);
        range_l = l, range_r = r;
    }

    void lazyUpdate(int n, int l, int r){
        if(lazy[n] == DEF) return;
        UPDATE(V[n], lazy[n]);
        if(l < r){
            UPDATE(lazy[2*n], lazy[n]);
            UPDATE(lazy[2*n+1], lazy[n]);
        }
        lazy[n] = DEF;
    }

    void update(int n, int l, int r, int L, int R, T val){
        lazyUpdate(n, l, r);
        if(r < L or R < l) return;
        if(L <= l and r <= R){
            UPDATE(lazy[n], val);
            lazyUpdate(n, l, r);
            return;
        }

        int m = (l+r)/2;
        update(n*2, l, m, L, R, val);
        update(n*2+1, m+1, r, L, R, val);
        V[n] = MERGE(V[n*2], V[n*2+1]);
    }

    T query(int n, int l, int r, int L, int R){
        lazyUpdate(n, l, r);
        if(r < L or R < l) return DEF;
        if(L <= l and r <= R) return V[n];

        int m = (l+r)/2;
        return MERGE(query(n*2, l, m, L, R),
        query(n*2+1, m+1, r, L, R));
    }

    void update(int L, T val){
        update(1, range_l, range_r, L, L, val);
    }
    T query(int L, int R){
        if(L <= R) return query(1, range_l, range_r, L, R);
        return min(query(1, range_l, range_r, L, range_r),
            query(1, range_l, range_r, 0, R)); 
    }
};

void seg_upd(int &a, int b){a = b;}
int seg_merge(int a, int b){return min(a, b);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int N; cin >> N;
    vi V(N); for(auto &i : V) cin >> i;

    auto bb = [&](int x){
        return (x+N)%N;
    };

    vi sum(N); int sz = (N+1)/2;
    sum[sz-1] = accumulate(V.begin(), V.begin()+sz, 0);

    for(int x = sz; x != sz-1; x = bb(x+1)){
        sum[x] = V[x]+sum[bb(x-1)]-V[bb(x-sz)];
    }

    SEGMENT_TREE<int, seg_upd, seg_merge> ST(0, N-1, INF);
    for(int x = 0; x < N; x++) ST.update(x, sum[x]); 

    int ans = 0;
    for(int x = 0; x < N; x++)
        ans = max(ans, ST.query(x, bb(x+sz-1)));

    cout << ans << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 4 ms 532 KB Output is correct
24 Correct 4 ms 332 KB Output is correct
25 Correct 4 ms 460 KB Output is correct
26 Correct 4 ms 460 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 4 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 4 ms 456 KB Output is correct
4 Correct 70 ms 3692 KB Output is correct
5 Correct 145 ms 8900 KB Output is correct
6 Correct 189 ms 11188 KB Output is correct
7 Correct 228 ms 13416 KB Output is correct
8 Correct 388 ms 22068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 4 ms 532 KB Output is correct
24 Correct 4 ms 332 KB Output is correct
25 Correct 4 ms 460 KB Output is correct
26 Correct 4 ms 460 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 4 ms 460 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 316 KB Output is correct
34 Correct 4 ms 456 KB Output is correct
35 Correct 70 ms 3692 KB Output is correct
36 Correct 145 ms 8900 KB Output is correct
37 Correct 189 ms 11188 KB Output is correct
38 Correct 228 ms 13416 KB Output is correct
39 Correct 388 ms 22068 KB Output is correct
40 Correct 7 ms 768 KB Output is correct
41 Correct 14 ms 1200 KB Output is correct
42 Correct 20 ms 1564 KB Output is correct
43 Correct 145 ms 9028 KB Output is correct
44 Correct 391 ms 22072 KB Output is correct
45 Correct 73 ms 4548 KB Output is correct
46 Correct 225 ms 13256 KB Output is correct
47 Correct 411 ms 22096 KB Output is correct
48 Correct 410 ms 22340 KB Output is correct
49 Correct 392 ms 21472 KB Output is correct
50 Correct 391 ms 21480 KB Output is correct