Submission #781841

# Submission time Handle Problem Language Result Execution time Memory
781841 2023-07-13T11:53:57 Z TeaTime Two Dishes (JOI19_dishes) C++17
74 / 100
6915 ms 515244 KB
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <cassert>

using namespace std;

typedef long long ll;
typedef long double ld;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SZ = 1'000'100, INF = 2'000'000'000'000'000'000;

ll n, m;

struct el {
    ll a, s, p;
};

vector<el> vec1, vec2;
vector<ll> pref1, pref2;

struct point {
    ll x, y, val;
};

vector<point> blue, red;

ll seg[SZ * 8], psh[SZ * 8];

void push(int v) {
    seg[v * 2 + 1] += psh[v];
    seg[v * 2 + 2] += psh[v];

    psh[v * 2 + 1] += psh[v];
    psh[v * 2 + 2] += psh[v];

    psh[v] = 0;
}

void upd(int v, int l, int r, int askl, int askr, ll val) {
    push(v);
    if (l >= askr || r <= askl) return;

    if (askl <= l && r <= askr) {
        seg[v] += val;
        psh[v] += val;
        return;
    }

    int mid = (l + r) / 2;
    upd(v * 2 + 1, l, mid, askl, askr, val);
    upd(v * 2 + 2, mid, r, askl, askr, val);
    seg[v] = max(seg[v * 2 + 1], seg[v * 2 + 2]);
}

void upd(int v, int l, int r, int pos, ll val) {
    push(v);
    if (l == r - 1) {
        seg[v] = val;
    } else {
        int mid = (l + r) / 2;

        if (pos < mid) {
            upd(v * 2 + 1, l, mid, pos, val);
        } else {
            upd(v * 2 + 2, mid, r, pos, val);
        }

        seg[v] = max(seg[v * 2 + 1], seg[v * 2 + 2]);
    }
}

ll ask(int v, int l, int r, int askl, int askr) {
    push(v);
    if (l >= askr || r <= askl) return -INF;

    if (askl <= l && r <= askr) return seg[v];

    int mid = (l + r) / 2;
    return max(ask(v * 2 + 1, l, mid, askl, askr), ask(v * 2 + 2, mid, r, askl, askr));
}

vector<point> points[SZ];

bool cmp(point a, point b) {
    return a.y < b.y;
}

int main() {
    fastInp;

    cin >> n >> m;

    vec1.resize(n);
    vec2.resize(m);

    pref1.push_back(0);
    for (auto &c : vec1) {
        cin >> c.a >> c.s >> c.p;
        pref1.push_back(pref1.back() + c.a);
    }

    pref2.push_back(0);
    for (auto &c : vec2) {
        cin >> c.a >> c.s >> c.p;
        pref2.push_back(pref2.back() + c.a);
    }

    for (int i = 0; i < SZ; i++) {
        seg[i] = -INF;
    }

    upd(0, 0, SZ, 0, 0);

    // x is vec1
    // y is vec2
    ll ans = 0, prefsum = 0;
    for (int i = 0; i < n; i++) {
        prefsum += vec1[i].a;

        ll left = vec1[i].s - prefsum;
        if (left < 0) continue;

        int ind = upper_bound(pref2.begin(), pref2.end(), left) - pref2.begin() - 1;
        assert(ind >= 0);

        blue.push_back({i + 1, ind, vec1[i].p}); // above or on the lattice path
    }

    prefsum = 0;

    for (int i = 0; i < m; i++) {
        prefsum += vec2[i].a;

        ll left = vec2[i].s - prefsum;
        if (left < 0) continue;

        int ind = upper_bound(pref1.begin(), pref1.end(), left) - pref1.begin() - 1;
        assert(ind >= 0);

        red.push_back({ind, i + 1, vec2[i].p}); // under or on the lattice path
        blue.push_back({ind + 1, i, -vec2[i].p}); // above or on the lattice path
        ans += vec2[i].p;
    }

    for (auto c : blue) {
        points[c.x].push_back(c);
        if (c.x != 0) points[c.x - 1].push_back({c.x - 1, c.y + 1, 0});
        if (c.x != 0) points[c.x - 1].push_back({c.x - 1, c.y, 0});
    }

    for (int i = 0; i < SZ; i++) {
        sort(points[i].begin(), points[i].end(), cmp);

        vector<point> cur;
        for (auto c : points[i]) {
            if (!cur.empty() && cur.back().y == c.y) {
                cur.back().val += c.val;
            } else {
                cur.push_back(c);
            }
        }

        points[i] = cur;

        ll prev = -1;

        for (auto c : points[i]) {
            upd(0, 0, SZ, 0, c.y + 1, c.val);
            ll q = ask(0, 0, SZ, 0, c.y + 1);
            upd(0, 0, SZ, c.y, q);
            prev = c.y;
        }
    }

    cout << ans + ask(0, 0, SZ, 0, SZ);

    return 0;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:170:12: warning: variable 'prev' set but not used [-Wunused-but-set-variable]
  170 |         ll prev = -1;
      |            ^~~~
# Verdict Execution time Memory Grader output
1 Correct 470 ms 106496 KB Output is correct
2 Correct 521 ms 112916 KB Output is correct
3 Correct 679 ms 118184 KB Output is correct
4 Correct 323 ms 84680 KB Output is correct
5 Correct 20 ms 31700 KB Output is correct
6 Correct 524 ms 111064 KB Output is correct
7 Correct 330 ms 79896 KB Output is correct
8 Correct 321 ms 64616 KB Output is correct
9 Correct 665 ms 118172 KB Output is correct
10 Correct 406 ms 110524 KB Output is correct
11 Correct 626 ms 118196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 31720 KB Output is correct
2 Correct 22 ms 31664 KB Output is correct
3 Correct 18 ms 31700 KB Output is correct
4 Correct 22 ms 31740 KB Output is correct
5 Correct 18 ms 31624 KB Output is correct
6 Correct 18 ms 31700 KB Output is correct
7 Correct 19 ms 31624 KB Output is correct
8 Correct 20 ms 31700 KB Output is correct
9 Correct 18 ms 31620 KB Output is correct
10 Correct 19 ms 31620 KB Output is correct
11 Correct 19 ms 31736 KB Output is correct
12 Correct 19 ms 31648 KB Output is correct
13 Correct 19 ms 31640 KB Output is correct
14 Correct 19 ms 31740 KB Output is correct
15 Correct 18 ms 31700 KB Output is correct
16 Correct 18 ms 31700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 31720 KB Output is correct
2 Correct 22 ms 31664 KB Output is correct
3 Correct 18 ms 31700 KB Output is correct
4 Correct 22 ms 31740 KB Output is correct
5 Correct 18 ms 31624 KB Output is correct
6 Correct 18 ms 31700 KB Output is correct
7 Correct 19 ms 31624 KB Output is correct
8 Correct 20 ms 31700 KB Output is correct
9 Correct 18 ms 31620 KB Output is correct
10 Correct 19 ms 31620 KB Output is correct
11 Correct 19 ms 31736 KB Output is correct
12 Correct 19 ms 31648 KB Output is correct
13 Correct 19 ms 31640 KB Output is correct
14 Correct 19 ms 31740 KB Output is correct
15 Correct 18 ms 31700 KB Output is correct
16 Correct 18 ms 31700 KB Output is correct
17 Correct 29 ms 32488 KB Output is correct
18 Correct 25 ms 32524 KB Output is correct
19 Correct 28 ms 32664 KB Output is correct
20 Correct 25 ms 32328 KB Output is correct
21 Correct 33 ms 32596 KB Output is correct
22 Correct 27 ms 32640 KB Output is correct
23 Correct 27 ms 32628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 31720 KB Output is correct
2 Correct 22 ms 31664 KB Output is correct
3 Correct 18 ms 31700 KB Output is correct
4 Correct 22 ms 31740 KB Output is correct
5 Correct 18 ms 31624 KB Output is correct
6 Correct 18 ms 31700 KB Output is correct
7 Correct 19 ms 31624 KB Output is correct
8 Correct 20 ms 31700 KB Output is correct
9 Correct 18 ms 31620 KB Output is correct
10 Correct 19 ms 31620 KB Output is correct
11 Correct 19 ms 31736 KB Output is correct
12 Correct 19 ms 31648 KB Output is correct
13 Correct 19 ms 31640 KB Output is correct
14 Correct 19 ms 31740 KB Output is correct
15 Correct 18 ms 31700 KB Output is correct
16 Correct 18 ms 31700 KB Output is correct
17 Correct 29 ms 32488 KB Output is correct
18 Correct 25 ms 32524 KB Output is correct
19 Correct 28 ms 32664 KB Output is correct
20 Correct 25 ms 32328 KB Output is correct
21 Correct 33 ms 32596 KB Output is correct
22 Correct 27 ms 32640 KB Output is correct
23 Correct 27 ms 32628 KB Output is correct
24 Correct 538 ms 115096 KB Output is correct
25 Correct 550 ms 114680 KB Output is correct
26 Correct 663 ms 115200 KB Output is correct
27 Correct 640 ms 111544 KB Output is correct
28 Correct 764 ms 124012 KB Output is correct
29 Correct 648 ms 129492 KB Output is correct
30 Correct 1183 ms 124660 KB Output is correct
31 Correct 403 ms 89380 KB Output is correct
32 Correct 354 ms 69832 KB Output is correct
33 Correct 618 ms 94488 KB Output is correct
34 Correct 1022 ms 125308 KB Output is correct
35 Correct 1167 ms 118768 KB Output is correct
36 Correct 1088 ms 118040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 31720 KB Output is correct
2 Correct 22 ms 31664 KB Output is correct
3 Correct 18 ms 31700 KB Output is correct
4 Correct 22 ms 31740 KB Output is correct
5 Correct 18 ms 31624 KB Output is correct
6 Correct 18 ms 31700 KB Output is correct
7 Correct 19 ms 31624 KB Output is correct
8 Correct 20 ms 31700 KB Output is correct
9 Correct 18 ms 31620 KB Output is correct
10 Correct 19 ms 31620 KB Output is correct
11 Correct 19 ms 31736 KB Output is correct
12 Correct 19 ms 31648 KB Output is correct
13 Correct 19 ms 31640 KB Output is correct
14 Correct 19 ms 31740 KB Output is correct
15 Correct 18 ms 31700 KB Output is correct
16 Correct 18 ms 31700 KB Output is correct
17 Correct 29 ms 32488 KB Output is correct
18 Correct 25 ms 32524 KB Output is correct
19 Correct 28 ms 32664 KB Output is correct
20 Correct 25 ms 32328 KB Output is correct
21 Correct 33 ms 32596 KB Output is correct
22 Correct 27 ms 32640 KB Output is correct
23 Correct 27 ms 32628 KB Output is correct
24 Correct 538 ms 115096 KB Output is correct
25 Correct 550 ms 114680 KB Output is correct
26 Correct 663 ms 115200 KB Output is correct
27 Correct 640 ms 111544 KB Output is correct
28 Correct 764 ms 124012 KB Output is correct
29 Correct 648 ms 129492 KB Output is correct
30 Correct 1183 ms 124660 KB Output is correct
31 Correct 403 ms 89380 KB Output is correct
32 Correct 354 ms 69832 KB Output is correct
33 Correct 618 ms 94488 KB Output is correct
34 Correct 1022 ms 125308 KB Output is correct
35 Correct 1167 ms 118768 KB Output is correct
36 Correct 1088 ms 118040 KB Output is correct
37 Correct 601 ms 118212 KB Output is correct
38 Correct 559 ms 114592 KB Output is correct
39 Correct 433 ms 121708 KB Output is correct
40 Correct 460 ms 121664 KB Output is correct
41 Correct 18 ms 31700 KB Output is correct
42 Correct 1148 ms 127848 KB Output is correct
43 Correct 624 ms 97556 KB Output is correct
44 Correct 1118 ms 127992 KB Output is correct
45 Correct 1126 ms 121852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 31720 KB Output is correct
2 Correct 22 ms 31664 KB Output is correct
3 Correct 18 ms 31700 KB Output is correct
4 Correct 22 ms 31740 KB Output is correct
5 Correct 18 ms 31624 KB Output is correct
6 Correct 18 ms 31700 KB Output is correct
7 Correct 19 ms 31624 KB Output is correct
8 Correct 20 ms 31700 KB Output is correct
9 Correct 18 ms 31620 KB Output is correct
10 Correct 19 ms 31620 KB Output is correct
11 Correct 19 ms 31736 KB Output is correct
12 Correct 19 ms 31648 KB Output is correct
13 Correct 19 ms 31640 KB Output is correct
14 Correct 19 ms 31740 KB Output is correct
15 Correct 18 ms 31700 KB Output is correct
16 Correct 18 ms 31700 KB Output is correct
17 Correct 29 ms 32488 KB Output is correct
18 Correct 25 ms 32524 KB Output is correct
19 Correct 28 ms 32664 KB Output is correct
20 Correct 25 ms 32328 KB Output is correct
21 Correct 33 ms 32596 KB Output is correct
22 Correct 27 ms 32640 KB Output is correct
23 Correct 27 ms 32628 KB Output is correct
24 Correct 538 ms 115096 KB Output is correct
25 Correct 550 ms 114680 KB Output is correct
26 Correct 663 ms 115200 KB Output is correct
27 Correct 640 ms 111544 KB Output is correct
28 Correct 764 ms 124012 KB Output is correct
29 Correct 648 ms 129492 KB Output is correct
30 Correct 1183 ms 124660 KB Output is correct
31 Correct 403 ms 89380 KB Output is correct
32 Correct 354 ms 69832 KB Output is correct
33 Correct 618 ms 94488 KB Output is correct
34 Correct 1022 ms 125308 KB Output is correct
35 Correct 1167 ms 118768 KB Output is correct
36 Correct 1088 ms 118040 KB Output is correct
37 Correct 601 ms 118212 KB Output is correct
38 Correct 559 ms 114592 KB Output is correct
39 Correct 433 ms 121708 KB Output is correct
40 Correct 460 ms 121664 KB Output is correct
41 Correct 18 ms 31700 KB Output is correct
42 Correct 1148 ms 127848 KB Output is correct
43 Correct 624 ms 97556 KB Output is correct
44 Correct 1118 ms 127992 KB Output is correct
45 Correct 1126 ms 121852 KB Output is correct
46 Correct 2972 ms 456472 KB Output is correct
47 Correct 2970 ms 447560 KB Output is correct
48 Correct 2159 ms 482876 KB Output is correct
49 Correct 2102 ms 482764 KB Output is correct
50 Correct 6915 ms 515244 KB Output is correct
51 Correct 3637 ms 358924 KB Output is correct
52 Correct 5493 ms 497428 KB Output is correct
53 Correct 6578 ms 478204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 470 ms 106496 KB Output is correct
2 Correct 521 ms 112916 KB Output is correct
3 Correct 679 ms 118184 KB Output is correct
4 Correct 323 ms 84680 KB Output is correct
5 Correct 20 ms 31700 KB Output is correct
6 Correct 524 ms 111064 KB Output is correct
7 Correct 330 ms 79896 KB Output is correct
8 Correct 321 ms 64616 KB Output is correct
9 Correct 665 ms 118172 KB Output is correct
10 Correct 406 ms 110524 KB Output is correct
11 Correct 626 ms 118196 KB Output is correct
12 Correct 18 ms 31720 KB Output is correct
13 Correct 22 ms 31664 KB Output is correct
14 Correct 18 ms 31700 KB Output is correct
15 Correct 22 ms 31740 KB Output is correct
16 Correct 18 ms 31624 KB Output is correct
17 Correct 18 ms 31700 KB Output is correct
18 Correct 19 ms 31624 KB Output is correct
19 Correct 20 ms 31700 KB Output is correct
20 Correct 18 ms 31620 KB Output is correct
21 Correct 19 ms 31620 KB Output is correct
22 Correct 19 ms 31736 KB Output is correct
23 Correct 19 ms 31648 KB Output is correct
24 Correct 19 ms 31640 KB Output is correct
25 Correct 19 ms 31740 KB Output is correct
26 Correct 18 ms 31700 KB Output is correct
27 Correct 18 ms 31700 KB Output is correct
28 Correct 29 ms 32488 KB Output is correct
29 Correct 25 ms 32524 KB Output is correct
30 Correct 28 ms 32664 KB Output is correct
31 Correct 25 ms 32328 KB Output is correct
32 Correct 33 ms 32596 KB Output is correct
33 Correct 27 ms 32640 KB Output is correct
34 Correct 27 ms 32628 KB Output is correct
35 Correct 538 ms 115096 KB Output is correct
36 Correct 550 ms 114680 KB Output is correct
37 Correct 663 ms 115200 KB Output is correct
38 Correct 640 ms 111544 KB Output is correct
39 Correct 764 ms 124012 KB Output is correct
40 Correct 648 ms 129492 KB Output is correct
41 Correct 1183 ms 124660 KB Output is correct
42 Correct 403 ms 89380 KB Output is correct
43 Correct 354 ms 69832 KB Output is correct
44 Correct 618 ms 94488 KB Output is correct
45 Correct 1022 ms 125308 KB Output is correct
46 Correct 1167 ms 118768 KB Output is correct
47 Correct 1088 ms 118040 KB Output is correct
48 Correct 601 ms 118212 KB Output is correct
49 Correct 559 ms 114592 KB Output is correct
50 Correct 433 ms 121708 KB Output is correct
51 Correct 460 ms 121664 KB Output is correct
52 Correct 18 ms 31700 KB Output is correct
53 Correct 1148 ms 127848 KB Output is correct
54 Correct 624 ms 97556 KB Output is correct
55 Correct 1118 ms 127992 KB Output is correct
56 Correct 1126 ms 121852 KB Output is correct
57 Incorrect 700 ms 118732 KB Output isn't correct
58 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 470 ms 106496 KB Output is correct
2 Correct 521 ms 112916 KB Output is correct
3 Correct 679 ms 118184 KB Output is correct
4 Correct 323 ms 84680 KB Output is correct
5 Correct 20 ms 31700 KB Output is correct
6 Correct 524 ms 111064 KB Output is correct
7 Correct 330 ms 79896 KB Output is correct
8 Correct 321 ms 64616 KB Output is correct
9 Correct 665 ms 118172 KB Output is correct
10 Correct 406 ms 110524 KB Output is correct
11 Correct 626 ms 118196 KB Output is correct
12 Correct 18 ms 31720 KB Output is correct
13 Correct 22 ms 31664 KB Output is correct
14 Correct 18 ms 31700 KB Output is correct
15 Correct 22 ms 31740 KB Output is correct
16 Correct 18 ms 31624 KB Output is correct
17 Correct 18 ms 31700 KB Output is correct
18 Correct 19 ms 31624 KB Output is correct
19 Correct 20 ms 31700 KB Output is correct
20 Correct 18 ms 31620 KB Output is correct
21 Correct 19 ms 31620 KB Output is correct
22 Correct 19 ms 31736 KB Output is correct
23 Correct 19 ms 31648 KB Output is correct
24 Correct 19 ms 31640 KB Output is correct
25 Correct 19 ms 31740 KB Output is correct
26 Correct 18 ms 31700 KB Output is correct
27 Correct 18 ms 31700 KB Output is correct
28 Correct 29 ms 32488 KB Output is correct
29 Correct 25 ms 32524 KB Output is correct
30 Correct 28 ms 32664 KB Output is correct
31 Correct 25 ms 32328 KB Output is correct
32 Correct 33 ms 32596 KB Output is correct
33 Correct 27 ms 32640 KB Output is correct
34 Correct 27 ms 32628 KB Output is correct
35 Correct 538 ms 115096 KB Output is correct
36 Correct 550 ms 114680 KB Output is correct
37 Correct 663 ms 115200 KB Output is correct
38 Correct 640 ms 111544 KB Output is correct
39 Correct 764 ms 124012 KB Output is correct
40 Correct 648 ms 129492 KB Output is correct
41 Correct 1183 ms 124660 KB Output is correct
42 Correct 403 ms 89380 KB Output is correct
43 Correct 354 ms 69832 KB Output is correct
44 Correct 618 ms 94488 KB Output is correct
45 Correct 1022 ms 125308 KB Output is correct
46 Correct 1167 ms 118768 KB Output is correct
47 Correct 1088 ms 118040 KB Output is correct
48 Correct 601 ms 118212 KB Output is correct
49 Correct 559 ms 114592 KB Output is correct
50 Correct 433 ms 121708 KB Output is correct
51 Correct 460 ms 121664 KB Output is correct
52 Correct 18 ms 31700 KB Output is correct
53 Correct 1148 ms 127848 KB Output is correct
54 Correct 624 ms 97556 KB Output is correct
55 Correct 1118 ms 127992 KB Output is correct
56 Correct 1126 ms 121852 KB Output is correct
57 Correct 2972 ms 456472 KB Output is correct
58 Correct 2970 ms 447560 KB Output is correct
59 Correct 2159 ms 482876 KB Output is correct
60 Correct 2102 ms 482764 KB Output is correct
61 Correct 6915 ms 515244 KB Output is correct
62 Correct 3637 ms 358924 KB Output is correct
63 Correct 5493 ms 497428 KB Output is correct
64 Correct 6578 ms 478204 KB Output is correct
65 Incorrect 700 ms 118732 KB Output isn't correct
66 Halted 0 ms 0 KB -