Submission #887554

# Submission time Handle Problem Language Result Execution time Memory
887554 2023-12-14T18:25:33 Z viwlesxq Divide and conquer (IZhO14_divide) C++17
100 / 100
84 ms 12628 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()

template<class S, class T> 
bool chmin(S &a, const T &b) {
    return (a > b ? (a = b) == b : false);
}
template<class S, class T> 
bool chmax(S &a, const T &b) {
    return (a < b ? (a = b) == b : false);
}
const ll inf = 1e18;
const int mod = 1e9 + 7;

struct Segment_Tree {
    int n;
    vector<ll> t, modify;
    Segment_Tree(int n) {
        this->n = n;
        t.assign(4 * n, -inf);
        modify.assign(4 * n, 0);
    }
    
    void push(int v, int tl, int tr) {
        t[v] += modify[v];
        if (tl != tr) {
            modify[2 * v] += modify[v];
            modify[2 * v + 1] += modify[v];
        }
        modify[v] = 0;
    }
    
    void upd_pos(int v, int tl, int tr, int i, ll x) {
        if (tl == tr) {
            t[v] = x;
            return;
        }
        int tm = (tl + tr) >> 1;
        if (tm >= i) {
            upd_pos(2 * v, tl, tm, i, x);
        } else {
            upd_pos(2 * v + 1, tm + 1, tr, i, x);
        }
        t[v] = max(t[2 * v], t[2 * v + 1]);
    } void upd_pos(int i, ll x) {
        upd_pos(1, 0, n - 1, i, x);
    }
    
    void upd(int v, int tl, int tr, int l, int r, ll x) {
        if (modify[v]) {
            push(v, tl, tr);
        }
        if (tl > r || tr < l) {
            return;
        }
        if (tl >= l && tr <= r) {
            modify[v] += x;
            push(v, tl, tr);
            return;
        }
        int tm = (tl + tr) >> 1;
        upd(2 * v, tl, tm, l, r, x);
        upd(2 * v + 1, tm + 1, tr, l, r, x);
        t[v] = max(t[2 * v], t[2 * v + 1]);
    } void upd(int l, int r, ll x) {
        upd(1, 0, n - 1, l, r, x);
    }
    
    int get(int v, int tl, int tr) {
        if (modify[v]) {
            push(v, tl, tr);
        }
        if (tl == tr) {
            return tl;
        }
        int tm = (tl + tr) >> 1;
        if (t[2 * v + 1] + modify[2 * v + 1] >= 0) {
            return get(2 * v + 1, tm + 1, tr);
        }
        return get(2 * v, tl, tm);
    } int get(int i) {
        return get(1, 0, n - 1);
    }
};

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    ll x[n], g[n], d[n], pref[n];
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> g[i] >> d[i];
    }
    Segment_Tree t(n);
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        sum += d[i];
        t.upd_pos(i, sum - x[i] + x[0]);
        pref[i] = (i == 0 ? 0 : pref[i - 1]) + g[i];
    }
    auto gold = [&](int l, int r) -> ll {
        return pref[r] - (l == 0 ? 0 : pref[l - 1]);
    };
    ll res = gold(0, t.get(0));
    for (int i = 1; i < n; ++i) {
        t.upd(i, n - 1, x[i] - x[i - 1] - d[i - 1]);
        chmax(res, gold(i, t.get(i)));
    }
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 416 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 3 ms 860 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 416 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 3 ms 860 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
25 Correct 3 ms 860 KB Output is correct
26 Correct 6 ms 1372 KB Output is correct
27 Correct 6 ms 1464 KB Output is correct
28 Correct 35 ms 5972 KB Output is correct
29 Correct 38 ms 6448 KB Output is correct
30 Correct 84 ms 12628 KB Output is correct
31 Correct 73 ms 11576 KB Output is correct
32 Correct 74 ms 11668 KB Output is correct
33 Correct 75 ms 11476 KB Output is correct
34 Correct 57 ms 11476 KB Output is correct
35 Correct 63 ms 11900 KB Output is correct
36 Correct 57 ms 12112 KB Output is correct