Submission #945267

# Submission time Handle Problem Language Result Execution time Memory
945267 2024-03-13T15:32:23 Z fzyzzz_z Divide and conquer (IZhO14_divide) C++17
100 / 100
113 ms 27332 KB
#include <bits/stdc++.h>
using namespace std; 

using ll = long long; 

const ll inf = 1e18 + 50;

struct Z {
    ll x, y, v; 
    Z() {}
};

ll t[262144 * 2];  
void upd(int x, ll v, int L = 0, int R = 262144 - 1, int at = 1) {
    if (x < L || x > R) return; 
    t[at] = min(t[at], v); 
    if (L == R) return; 
    int mid = (L + R) / 2; 
    upd(x, v, L, mid, at * 2); 
    upd(x, v, mid + 1, R, at * 2 + 1); 
}

ll query(int l, int r, int L = 0, int R = 262144 - 1, int at = 1) {
    if (l > R || L > r) return (1LL << 60); 
    if (l <= L && R <= r) {
        return t[at]; 
    }
    int mid = (L + R) / 2; 
    ll x = query(l, r, L, mid, at * 2); 
    ll y = query(l, r, mid + 1, R, at * 2 + 1); 
    return min(x, y); 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    for (int i = 0; i < 262144 * 2; ++i) t[i] = (1LL << 60); 

    int n; 
    cin >> n; 
    vector<Z> a(n); 
    vector<pair<ll, ll>> xs;
    vector<ll> gx(n), ex(n); 

    ll e = 0, g = 0; 
    for (int i = 0; i < n; ++i) {
        ll x, y, z; 
        cin >> x >> y >> z; 

        gx[i] = y; 
        ex[i] = z; 

        a[i].x = x; 
        a[i].y = e; 
        a[i].v = g;

        xs.push_back({e - x, i}); 
        xs.push_back({e + z - x, i}); 

        g += y; 
        e += z;
    }
    sort(xs.begin(), xs.end()); 
    map<pair<ll, ll>, int> to; 
    for (int i = 0; i < 2 * n; ++i) {
        // cout << xs[i].first << ' ' << xs[i].second << '\n';
        to[xs[i]] = i; 
    }
    ll ans = 0; 
    for (int i = 0; i < n; ++i) {
        int c = to[make_pair(a[i].y - a[i].x, i)]; 
        upd(c, a[i].v); 
        // cout << "updating " << c << ' ' << a[i].v << '\n';

        c = to[make_pair(a[i].y + ex[i] - a[i].x, i)]; 
        ans = max(ans, a[i].v + gx[i] - query(0, c)); 

        // cout << "! proc " << i << '\n';
        // cout << c << ' ' << query(0, c) << '\n';
        // cout << a[i].v + gx[i] - query(0, c) << '\n';
    }

    cout << ans << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4560 KB Output is correct
8 Correct 2 ms 4524 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4560 KB Output is correct
8 Correct 2 ms 4524 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 3 ms 4444 KB Output is correct
14 Correct 3 ms 4488 KB Output is correct
15 Correct 2 ms 4696 KB Output is correct
16 Correct 2 ms 4700 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 3 ms 4700 KB Output is correct
19 Correct 3 ms 4700 KB Output is correct
20 Correct 3 ms 4700 KB Output is correct
21 Correct 3 ms 4876 KB Output is correct
22 Correct 4 ms 4956 KB Output is correct
23 Correct 5 ms 5592 KB Output is correct
24 Correct 6 ms 5592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4560 KB Output is correct
8 Correct 2 ms 4524 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 3 ms 4444 KB Output is correct
14 Correct 3 ms 4488 KB Output is correct
15 Correct 2 ms 4696 KB Output is correct
16 Correct 2 ms 4700 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 3 ms 4700 KB Output is correct
19 Correct 3 ms 4700 KB Output is correct
20 Correct 3 ms 4700 KB Output is correct
21 Correct 3 ms 4876 KB Output is correct
22 Correct 4 ms 4956 KB Output is correct
23 Correct 5 ms 5592 KB Output is correct
24 Correct 6 ms 5592 KB Output is correct
25 Correct 6 ms 5592 KB Output is correct
26 Correct 10 ms 6612 KB Output is correct
27 Correct 19 ms 6612 KB Output is correct
28 Correct 84 ms 15328 KB Output is correct
29 Correct 54 ms 15564 KB Output is correct
30 Correct 103 ms 27332 KB Output is correct
31 Correct 101 ms 26568 KB Output is correct
32 Correct 98 ms 26440 KB Output is correct
33 Correct 100 ms 25540 KB Output is correct
34 Correct 101 ms 26136 KB Output is correct
35 Correct 113 ms 26668 KB Output is correct
36 Correct 100 ms 26528 KB Output is correct