답안 #887304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887304 2023-12-14T08:50:20 Z viwlesxq 금 캐기 (IZhO14_divide) C++17
0 / 100
1 ms 344 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 = 1e9;
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, 0);
        modify.assign(4 * n, 0);
    }
    
    void push(int v, int tl, int tr) {
        t[v] += modify[v] * (tr - tl + 1);
        if (tl != tr) {
            modify[2 * v] += modify[v];
            modify[2 * v + 1] += modify[v];
        }
        modify[v] = 0;
    }
    
    void upd(int v, int tl, int tr, int l, int r, int 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, int x) {
        upd(1, 0, n - 1, l, r, x);
    }
    
    ll get(int v, int tl, int tr, int l, int r) {
        if (modify[v]) {
            push(v, tl, tr);
        }
        if (tl > r || tr < l) {
            return -inf;
        }
        if (tl >= l && tr <= r) {
            return t[v];
        }
        int tm = (tl + tr) >> 1;
        return max(get(2 * v, tl, tm, l, r), get(2 * v + 1, tm + 1, tr, l, r));
    } int get(int i) {
        int lo = i, hi = n;
        while (lo + 1 < hi) {
            int mid = (lo + hi) >> 1;
            if (get(1, 0, n - 1, mid, n - 1) >= 0) {
                lo = mid;
            } else {
                hi = mid;
            }
        }
        return lo;
    }
};

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(i, i, sum - x[i] + x[0]);
        pref[i] = (i == 0 ? 0 : pref[i - 1]) + g[i];
    }
    auto gold = [&](int l, int r) {
        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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -