답안 #151351

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151351 2019-09-02T14:21:29 Z theboatman Bigger segments (IZhO19_segments) C++17
27 / 100
237 ms 262148 KB
#include <bits/stdc++.h>

#define y1 theboatman
#define make_struct(args...) {args}

#define int ll

using namespace std;

typedef long long ll;

const long long INF = 1e18 + 10;
const int inf = 1e9 + 10;
const int N = 1e6 + 10;

struct tree {
    struct node {
        int mx, add;
    };

    int v, tl, tr;
    vector <node> t;

    void build(int n) {
         v = 1;
         tl = 0;
         tr = n - 1;

         t.assign(n * 30, make_struct(-inf, -inf));
    }

    void push(int v, int deep) {
        if (deep == 2) {
            return;
        }

        t[v * 2].add = max(t[v * 2].add, t[v].add);
        t[v * 2 + 1].add = max(t[v * 2 + 1].add, t[v].add);

        push(v * 2, deep + 1);
        push(v * 2 + 1, deep + 1);
    }

    void modify(int v, int tl, int tr, int l, int r, int x) {
        if (l > r) {
            return;
        }

        if (tl == l && tr == r) {
            t[v].add = max(t[v].add, x);
            return;
        }

        int tm = (tl + tr) / 2;
        modify(v * 2, tl, tm, l, min(r, tm), x);
        modify(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, x);
    }

    int get(int v, int tl, int tr, int pos) {
        push(v, 0);

        if (tl == tr) {
            return t[v].add;
        }

        int tm = (tl + tr) / 2;
        if (pos <= tm) {
            return get(v * 2, tl, tm, pos);
        }
        else {
            return get(v * 2 + 1, tm + 1, tr, pos);
        }
    }

    int get(int pos) {
        return get(v, tl, tr, pos);
    }

    void modify(int l, int r, int x) {
        modify(v, tl, tr, l, r, x);
    }
};

tree dp[3010];
vector <int> pref;

int get(int l, int r) {
    int res = pref[r];

    return (l ? res - pref[l - 1] : res);
}

int32_t main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n;
    cin >> n;

    vector <int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for(int i = 0; i < n; i++) {
        dp[i].build(n);
    }

    dp[0].modify(0, n - 1, 1);

    pref.resize(n);
    for(int i = 0; i < n; i++) {
        pref[i] = (i ? pref[i - 1] + a[i] : a[i]);
    }


    for(int i = 0; i < n; i++) {
        for(int j = i; j < n; j++) {
            int l = j + 1, r = n;
            while(l < r) {
                int c = (l + r) / 2;
                if (get(i, j) > get(j + 1, c)) {
                    l = c + 1;
                }
                else {
                    r = c;
                }
            }

            l = j + 1;
            while(l < n && get(i, j) > get(j + 1, l)) {
                l++;
            }

            //cout << i << " " << j << " " << dp[i].get(j) + 1 << " " << l << " " << n - 1 << "\n";
            dp[j + 1].modify(l, n - 1, dp[i].get(j) + 1);
        }
    }

    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            ans = max(ans, dp[i].get(j));
        }
    }

    cout << ans << "\n";
    return 0;
}
/*
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 3 ms 632 KB Output is correct
15 Correct 2 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 3 ms 632 KB Output is correct
15 Correct 2 ms 632 KB Output is correct
16 Correct 227 ms 118784 KB Output is correct
17 Correct 225 ms 118776 KB Output is correct
18 Correct 225 ms 118800 KB Output is correct
19 Correct 221 ms 118776 KB Output is correct
20 Correct 224 ms 118780 KB Output is correct
21 Correct 224 ms 118900 KB Output is correct
22 Correct 141 ms 76024 KB Output is correct
23 Correct 81 ms 43768 KB Output is correct
24 Correct 222 ms 118732 KB Output is correct
25 Correct 226 ms 119032 KB Output is correct
26 Correct 229 ms 118776 KB Output is correct
27 Correct 230 ms 118776 KB Output is correct
28 Correct 237 ms 118776 KB Output is correct
29 Correct 220 ms 118716 KB Output is correct
30 Correct 225 ms 118776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 3 ms 632 KB Output is correct
15 Correct 2 ms 632 KB Output is correct
16 Correct 227 ms 118784 KB Output is correct
17 Correct 225 ms 118776 KB Output is correct
18 Correct 225 ms 118800 KB Output is correct
19 Correct 221 ms 118776 KB Output is correct
20 Correct 224 ms 118780 KB Output is correct
21 Correct 224 ms 118900 KB Output is correct
22 Correct 141 ms 76024 KB Output is correct
23 Correct 81 ms 43768 KB Output is correct
24 Correct 222 ms 118732 KB Output is correct
25 Correct 226 ms 119032 KB Output is correct
26 Correct 229 ms 118776 KB Output is correct
27 Correct 230 ms 118776 KB Output is correct
28 Correct 237 ms 118776 KB Output is correct
29 Correct 220 ms 118716 KB Output is correct
30 Correct 225 ms 118776 KB Output is correct
31 Runtime error 207 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 3 ms 632 KB Output is correct
15 Correct 2 ms 632 KB Output is correct
16 Correct 227 ms 118784 KB Output is correct
17 Correct 225 ms 118776 KB Output is correct
18 Correct 225 ms 118800 KB Output is correct
19 Correct 221 ms 118776 KB Output is correct
20 Correct 224 ms 118780 KB Output is correct
21 Correct 224 ms 118900 KB Output is correct
22 Correct 141 ms 76024 KB Output is correct
23 Correct 81 ms 43768 KB Output is correct
24 Correct 222 ms 118732 KB Output is correct
25 Correct 226 ms 119032 KB Output is correct
26 Correct 229 ms 118776 KB Output is correct
27 Correct 230 ms 118776 KB Output is correct
28 Correct 237 ms 118776 KB Output is correct
29 Correct 220 ms 118716 KB Output is correct
30 Correct 225 ms 118776 KB Output is correct
31 Runtime error 207 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 3 ms 632 KB Output is correct
15 Correct 2 ms 632 KB Output is correct
16 Correct 227 ms 118784 KB Output is correct
17 Correct 225 ms 118776 KB Output is correct
18 Correct 225 ms 118800 KB Output is correct
19 Correct 221 ms 118776 KB Output is correct
20 Correct 224 ms 118780 KB Output is correct
21 Correct 224 ms 118900 KB Output is correct
22 Correct 141 ms 76024 KB Output is correct
23 Correct 81 ms 43768 KB Output is correct
24 Correct 222 ms 118732 KB Output is correct
25 Correct 226 ms 119032 KB Output is correct
26 Correct 229 ms 118776 KB Output is correct
27 Correct 230 ms 118776 KB Output is correct
28 Correct 237 ms 118776 KB Output is correct
29 Correct 220 ms 118716 KB Output is correct
30 Correct 225 ms 118776 KB Output is correct
31 Runtime error 207 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
32 Halted 0 ms 0 KB -