Submission #986682

# Submission time Handle Problem Language Result Execution time Memory
986682 2024-05-21T03:32:13 Z JooDdae Salesman (IOI09_salesman) C++17
40 / 100
459 ms 48268 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define mid ((l+r) >> 1)

const int INF = 2e9, N = 2e5+1;

int n, u, d, s, mx[500500], t1[2002002], t2[2002002];
vector<array<int, 2>> v[500500];

void update(int t[], int id, int x, int node = 1, int l = 1, int r = N) {
    if(id < l || r < id) return;
    if(l == r) {
        t[node] = max(t[node], x);
        return;
    }
    update(t, id, x, node*2, l, mid), update(t, id, x, node*2+1, mid+1, r);
    t[node] = max(t[node*2], t[node*2+1]);
}

int find(int t[], int nl, int nr, int node = 1, int l = 1, int r = N) {
    if(nr < l || r < nl) return -INF;
    if(nl <= l && r <= nr) return t[node];
    return max(find(t, nl, nr, node*2, l, mid), find(t, nl, nr, node*2+1, mid+1, r));
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> u >> d >> s;
    for(int i=1;i<=n;i++) {
        int t, x, y; cin >> t >> x >> y;
        v[t].push_back({x, y});
    }

    fill(t1, t1+4*N+1, -INF), fill(t2, t2+4*N+1, -INF);
    fill(mx, mx+N+1, -INF);
    update(t1, s, s*u), update(t2, s, -s*d);
    for(int t=1;t<=N;t++) if(!v[t].empty()) {
        sort(v[t].begin(), v[t].end());

        for(auto [x, y] : v[t]) mx[x] = max(find(t1, 1, x-1) - x*u, x*d + find(t2, x+1, N)) + y;

        for(auto [x, y] : v[t]) {
            update(t1, x, x*u+mx[x]);
            update(t2, x, mx[x]-x*d);
        }

        for(auto [x, y] : v[t]) {
            auto k = find(t1, 1, x-1) - x*u + y;
            mx[x] = max(mx[x], k), update(t1, x, x*u+k);
        }
        reverse(v[t].begin(), v[t].end());
        for(auto [x, y] : v[t]) {
            auto k = x*d + find(t2, x+1, N) + y;
            mx[x] = max(mx[x], k), update(t2, x, k-x*d);
        }

        for(auto [x, y] : v[t]) {
            update(t1, x, x*u+mx[x]);
            update(t2, x, mx[x]-x*d);
        }
    }

    int ans = 0;
    for(int i=1;i<=N;i++) {
        ans = max(ans, find(t1, 1, s-1) - s*u);
        ans = max(ans, s*d + find(t2, s+1, N));
    }
    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 43 ms 23128 KB Output is correct
2 Correct 40 ms 23132 KB Output is correct
3 Correct 44 ms 23208 KB Output is correct
4 Correct 46 ms 23128 KB Output is correct
5 Correct 49 ms 23384 KB Output is correct
6 Incorrect 17 ms 24668 KB Output isn't correct
7 Incorrect 72 ms 25948 KB Output isn't correct
8 Incorrect 100 ms 28584 KB Output isn't correct
9 Incorrect 102 ms 30544 KB Output isn't correct
10 Correct 250 ms 37716 KB Output is correct
11 Incorrect 185 ms 38228 KB Output isn't correct
12 Correct 224 ms 42300 KB Output is correct
13 Incorrect 290 ms 42592 KB Output isn't correct
14 Incorrect 313 ms 48268 KB Output isn't correct
15 Incorrect 328 ms 47440 KB Output isn't correct
16 Incorrect 314 ms 47184 KB Output isn't correct
17 Correct 42 ms 23132 KB Output is correct
18 Correct 43 ms 23132 KB Output is correct
19 Correct 49 ms 23220 KB Output is correct
20 Correct 47 ms 23132 KB Output is correct
21 Correct 45 ms 23128 KB Output is correct
22 Correct 49 ms 23132 KB Output is correct
23 Correct 51 ms 23132 KB Output is correct
24 Correct 54 ms 23132 KB Output is correct
25 Incorrect 128 ms 25956 KB Output isn't correct
26 Incorrect 225 ms 28592 KB Output isn't correct
27 Incorrect 332 ms 31584 KB Output isn't correct
28 Incorrect 318 ms 32836 KB Output isn't correct
29 Incorrect 453 ms 34880 KB Output isn't correct
30 Incorrect 459 ms 36040 KB Output isn't correct