Submission #125601

# Submission time Handle Problem Language Result Execution time Memory
125601 2019-07-06T04:48:57 Z srvlt Divide and conquer (IZhO14_divide) C++14
17 / 100
32 ms 10744 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, 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));
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    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;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 3 ms 888 KB Output is correct
4 Correct 4 ms 1016 KB Output is correct
5 Correct 5 ms 1272 KB Output is correct
6 Incorrect 5 ms 1656 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 5624 KB Output is correct
2 Correct 32 ms 10744 KB Output is correct
3 Incorrect 26 ms 10676 KB Output isn't correct
4 Halted 0 ms 0 KB -