Submission #809751

# Submission time Handle Problem Language Result Execution time Memory
809751 2023-08-06T03:25:03 Z fanwen Divide and conquer (IZhO14_divide) C++17
100 / 100
41 ms 8404 KB
#include <bits/stdc++.h>

using namespace std;

#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }

template <class A, class B> bool minimize(A &a, B b)  { if (a > b) { a = b; return true; } return false; }
template <class A, class B> bool maximize(A &a, B b)  { if (a < b) { a = b; return true; } return false; }

const int MAXN = 1e5 + 5;
const long long INF = 1e18;
int N, x[MAXN];
long long dp[MAXN], d[MAXN], g[MAXN];

struct segment_tree {
    vector <long long> it;
    segment_tree(int n = 0) : it(n << 2 | 1, INF) {}

    void update(int idx, int l, int r, int u, long long val) {
        if(l > u || r < u) return;
        if(l == r) return void(it[idx] = val);
        int mid = l + r >> 1;
        update(idx << 1, l, mid, u, val);
        update(idx << 1 | 1, mid + 1, r, u, val);
        it[idx] = min(it[idx << 1], it[idx << 1 | 1]);
    }

    int find(int idx, int l, int r, long long val) {
        if(l == r) return l;
        int mid = l + r >> 1;
        return it[idx << 1] <= val ? find(idx << 1, l, mid, val) : find(idx << 1 | 1, mid + 1, r, val);
    }
};

void you_make_it(void) {
    cin >> N;
    long long res = 0;
    FOR(i, 1, N) {
        cin >> x[i] >> g[i] >> d[i];
        maximize(res, g[i]);
        d[i] += d[i - 1];
        g[i] += g[i - 1];
    }
    segment_tree it(N);
    it.update(1, 1, N, 1, -x[1]);
    FOR(i, 2, N) {
        int j = it.find(1, 1, N, d[i] - x[i]);
        maximize(res, g[i] - g[j - 1]);
        it.update(1, 1, N, i, d[i - 1] - x[i]);
    }
    cout << res;
}

signed main() {

#ifdef LOCAL
    freopen("TASK.inp", "r", stdin);
    freopen("TASK.out", "w", stdout);
#endif
    auto start_time = chrono::steady_clock::now();

    cin.tie(0), cout.tie(0) -> sync_with_stdio(0);

    you_make_it();

    auto end_time = chrono::steady_clock::now();

    cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl;

    return (0 ^ 0);
}

// Dream it. Wish it. Do it.

Compilation message

divide.cpp: In member function 'void segment_tree::update(int, int, int, int, long long int)':
divide.cpp:30:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |         int mid = l + r >> 1;
      |                   ~~^~~
divide.cpp: In member function 'int segment_tree::find(int, int, int, long long int)':
divide.cpp:38:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |         int mid = l + r >> 1;
      |                   ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 3 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 3 ms 768 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 3 ms 852 KB Output is correct
27 Correct 3 ms 972 KB Output is correct
28 Correct 16 ms 3796 KB Output is correct
29 Correct 17 ms 4252 KB Output is correct
30 Correct 41 ms 8404 KB Output is correct
31 Correct 40 ms 7080 KB Output is correct
32 Correct 30 ms 7216 KB Output is correct
33 Correct 29 ms 6996 KB Output is correct
34 Correct 33 ms 7048 KB Output is correct
35 Correct 33 ms 7536 KB Output is correct
36 Correct 38 ms 7624 KB Output is correct