답안 #125610

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125610 2019-07-06T05:20:55 Z srvlt 금 캐기 (IZhO14_divide) C++14
100 / 100
288 ms 105828 KB
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define int long long
#define val(x) (((x) == nullptr) ? 0 : (x -> m))
#define left(x) (((x) == nullptr) ? nullptr : (x -> l))
#define right(x) (((x) == nullptr) ? nullptr : (x -> r))
using namespace std;

const int N = 1e5 + 3, M = 2e9;
int n, x[N], d[N], g[N], v[N], ans;

struct node {
    node * l, * r;
    int m;
    node(node * l, node * r, int m = 0) {
        this -> l = l;
        this -> r = r;
        this -> m = m + max(val(l), val(r));
    }
};

node * root = new node(nullptr, nullptr);

node * update(node * t, int tl, int tr, int x, int y) {
    if (tl == tr) {
        return new node(nullptr, nullptr, max(val(t), y));
    }
    int tm = (tl + tr) >> 1LL;
    if (x <= tm) {
        return new node(update(left(t), tl, tm, x, y), right(t));
    }   else {
        return new node(left(t), update(right(t), tm + 1, tr, x, y));
    }
}

int getmax(node * t, int tl, int tr, int l, int r) {
    if (tl > r || tr < l) {
        return 0;
    }
    if (tl >= l && tr <= r) {
        return val(t);
    }
    int tm = (tl + tr) >> 1LL;
    return max(getmax(left(t), tl, tm, l, r), getmax(right(t), tm + 1, tr, l, r));
}

void cleanup() {
    root = new node(nullptr, nullptr);
    n = 0, ans = 0;
    for (int i = 0; i < N; i++) {
        x[i] = d[i] = g[i] = v[i] = 0;
    }
}

void solve() {
    cleanup();
    cin>>n;
    for (int i = 1; i <= n; i++) {
        cin>>x[i]>>g[i]>>d[i];
        g[i] += g[i - 1];
        d[i] += d[i - 1];
        v[i] = d[i] - x[i];
    }
    for (int i = n; i >= 1; i--) {
        int tmp = d[i - 1] - x[i];
        root = update(root, 0, M, v[i] + (int) 1e9, i);
        int res = getmax(root, 0, M, tmp + (int) 1e9, M);
        ans = max(ans, g[res] - g[i - 1]);
    }
    cout<<ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int tc = 1;
//    cin>>tc;
    while (tc--) {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3448 KB Output is correct
2 Correct 5 ms 3448 KB Output is correct
3 Correct 5 ms 3448 KB Output is correct
4 Correct 5 ms 3448 KB Output is correct
5 Correct 5 ms 3576 KB Output is correct
6 Correct 5 ms 3576 KB Output is correct
7 Correct 5 ms 3576 KB Output is correct
8 Correct 5 ms 3576 KB Output is correct
9 Correct 5 ms 3576 KB Output is correct
10 Correct 5 ms 3576 KB Output is correct
11 Correct 5 ms 3576 KB Output is correct
12 Correct 5 ms 3576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3704 KB Output is correct
2 Correct 5 ms 3696 KB Output is correct
3 Correct 6 ms 3960 KB Output is correct
4 Correct 7 ms 4088 KB Output is correct
5 Correct 7 ms 4344 KB Output is correct
6 Correct 7 ms 4600 KB Output is correct
7 Correct 8 ms 4472 KB Output is correct
8 Correct 8 ms 4472 KB Output is correct
9 Correct 9 ms 4984 KB Output is correct
10 Correct 10 ms 5496 KB Output is correct
11 Correct 19 ms 8596 KB Output is correct
12 Correct 19 ms 8636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 8440 KB Output is correct
2 Correct 32 ms 13432 KB Output is correct
3 Correct 28 ms 13308 KB Output is correct
4 Correct 118 ms 53084 KB Output is correct
5 Correct 122 ms 53368 KB Output is correct
6 Correct 249 ms 103432 KB Output is correct
7 Correct 227 ms 102392 KB Output is correct
8 Correct 232 ms 102392 KB Output is correct
9 Correct 279 ms 105132 KB Output is correct
10 Correct 280 ms 105156 KB Output is correct
11 Correct 284 ms 105596 KB Output is correct
12 Correct 288 ms 105828 KB Output is correct