답안 #951332

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
951332 2024-03-21T15:45:54 Z LOLOLO 금 캐기 (IZhO14_divide) C++17
100 / 100
101 ms 25668 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())

const int N = 2e5 + 100;
ll seg[N * 4], dp[N];
int n;

void point(int id, int l, int r, int p, ll v) {
    if (l > p || r < p)
        return;

    seg[id] = min(seg[id], v);
    if (l == r)
        return;

    int m = (l + r) / 2;
    point(id * 2, l, m, p, v);
    point(id * 2 + 1, m + 1, r, p, v);
}

ll get(int id, int l, int r, int u, int v) {
    if (l > v || r < u)
        return 1e18;

    if (l >= u && r <= v)
        return seg[id];

    int m = (l + r) / 2;
    return min(get(id * 2, l, m, u, v), get(id * 2 + 1, m + 1, r, u, v));
}

ll x[N], g[N], d[N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;

    fill(seg, seg + n * 8 + 10, 1e18);
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> g[i] >> d[i];
        g[i] += g[i - 1];
        d[i] += d[i - 1];
    }

    map <ll, int> mp;
    int timer = 1;
    for (int i = 1; i <= n; i++) {
        mp[x[i] - d[i - 1]];
        mp[x[i] - d[i]];
    }

    for (auto &x : mp) {
        x.s = timer;
        timer++;
    }

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        int p = mp[x[i] - d[i]];
        point(1, 1, n * 2, mp[x[i] - d[i - 1]], g[i - 1]);
        ans = max({ans, g[i] - get(1, 1, n * 2, p, n * 2)});
    }

    cout << ans << '\n';
    return 0;
}

/*
en[i] = g[1] + g[2] +..+ g[i];
s[i] =  d[1] + d[2] +..+ d[i];
dp[i] = tổng lớn nhất.
dp[i] = max(dp[i - 1], dp[j - 1] + en[i] - en[j - 1]); 
(x[i] - x[j] <= s[i] - s[j - 1])
<=> x[i] - s[i] <= x[j] - s[j - 1]
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6744 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6744 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 5 ms 9560 KB Output is correct
24 Correct 5 ms 9308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6744 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 5 ms 9560 KB Output is correct
24 Correct 5 ms 9308 KB Output is correct
25 Correct 5 ms 9308 KB Output is correct
26 Correct 7 ms 10000 KB Output is correct
27 Correct 8 ms 9780 KB Output is correct
28 Correct 42 ms 17092 KB Output is correct
29 Correct 38 ms 16984 KB Output is correct
30 Correct 95 ms 25424 KB Output is correct
31 Correct 91 ms 25668 KB Output is correct
32 Correct 101 ms 25360 KB Output is correct
33 Correct 86 ms 25428 KB Output is correct
34 Correct 85 ms 25012 KB Output is correct
35 Correct 86 ms 25484 KB Output is correct
36 Correct 80 ms 25424 KB Output is correct