Submission #479994

# Submission time Handle Problem Language Result Execution time Memory
479994 2021-10-14T07:14:25 Z Dima_Borchuk Divide and conquer (IZhO14_divide) C++17
100 / 100
193 ms 35320 KB
#pragma GCC optimize("Ofast")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) int32_t(x.size())
#define pii pair < int, int >
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define _ << ' ' <<
#define se second
#define fi first
#define int ll

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

const int mod = (int)1e9 + 9;
const int N = (int)1e6 + 5;
const int INF = (int)1e16 + 5;

struct point {
    int x, g, e;
};

struct segmentTree {
    vector < int > t;
    int s = 1;

    void build(int n) {
        t.resize(4 * n, INF);
        while (s < n) {
            s *= 2;
        }
    }

    int getMin(int v, int vl, int vr, int l, int r) {
        if (vl > r || vr < l) {
            return INF;
        }
        if (vl >= l && vr <= r) {
            return t[v];
        }

        int mid = (vl + vr) / 2;
        return min(getMin(v * 2, vl, mid, l, r), getMin(v * 2 + 1, mid + 1, vr, l, r));
    }

    void upd(int v, int vl, int vr, int pos, int x) {
        if (vl == vr) {
            t[v] = min(t[v], x);
            return;
        }

        int mid = (vl + vr) / 2;
        if (pos <= mid) {
            upd(v * 2, vl, mid, pos, x);
        }
        else {
            upd(v * 2 + 1, mid + 1, vr, pos, x);
        }
        t[v] = min(t[v * 2], t[v * 2 + 1]);
    }

    int getMin(int l, int r) {
        return getMin(1, 1, s, l, r);
    }

    void upd(int pos, int x) {
        upd(1, 1, s, pos, x);
    }
};

int32_t main() {
    #ifdef LOCAL
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
    #endif // LOCAL

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;
    cin >> n;
    vector < point > a(n + 1);
    vector < int > pe(n + 1, 0), pg(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> a[i].x >> a[i].g >> a[i].e;
        pe[i] = pe[i - 1] + a[i].e;
        pg[i] = pg[i - 1] + a[i].g;
    }

    set < int > all;
    map < int, int > mp;

    for (int i = 1; i <= n; i++) {
        all.insert(a[i].x - pe[i]);
        all.insert(a[i].x - pe[i - 1]);
    }
    int k = 0;
    for (auto i : all) {
        mp[i] = k++;
    }

    int ans = 0;
    segmentTree t;
    t.build(k);
    for (int i = 1; i <= n; i++) {
        t.upd(mp[a[i].x - pe[i - 1]], pg[i - 1]);
        ans = max(ans, pg[i] - t.getMin(mp[a[i].x - pe[i]], k));
    }

    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 2 ms 532 KB Output is correct
17 Correct 3 ms 588 KB Output is correct
18 Correct 2 ms 716 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 2 ms 584 KB Output is correct
21 Correct 3 ms 716 KB Output is correct
22 Correct 3 ms 972 KB Output is correct
23 Correct 8 ms 1996 KB Output is correct
24 Correct 8 ms 1996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 2 ms 532 KB Output is correct
17 Correct 3 ms 588 KB Output is correct
18 Correct 2 ms 716 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 2 ms 584 KB Output is correct
21 Correct 3 ms 716 KB Output is correct
22 Correct 3 ms 972 KB Output is correct
23 Correct 8 ms 1996 KB Output is correct
24 Correct 8 ms 1996 KB Output is correct
25 Correct 9 ms 1868 KB Output is correct
26 Correct 16 ms 3532 KB Output is correct
27 Correct 15 ms 3660 KB Output is correct
28 Correct 88 ms 17476 KB Output is correct
29 Correct 94 ms 17604 KB Output is correct
30 Correct 191 ms 35320 KB Output is correct
31 Correct 188 ms 34144 KB Output is correct
32 Correct 193 ms 34308 KB Output is correct
33 Correct 189 ms 33928 KB Output is correct
34 Correct 181 ms 33156 KB Output is correct
35 Correct 192 ms 34436 KB Output is correct
36 Correct 187 ms 34744 KB Output is correct