답안 #1072855

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072855 2024-08-24T05:49:57 Z Double_Slash Two Dishes (JOI19_dishes) C++17
100 / 100
4706 ms 298964 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll INF = 1e18;
int N, M, a[1000000], b[1000000], p[1000000], q[1000000];
ll s[1000000], t[1000000], psa[1000001], psb[1000001], off;
vector<int> rem[1000001];

struct Node {
    int l, r;
    ll val = 0, lazychmax = -INF, lazyadd = 0;
    Node *lc, *rc;

    Node(int l, int r) : l(l), r(r) {
        if (l < r) {
            int m = (l + r) >> 1;
            lc = new Node{l, m};
            rc = new Node{m + 1, r};
        }
    }

    void clean() {
        if (lazychmax != -INF) {
            if (l == r) val = max(val, lazychmax);
            else {
                lc->lazychmax = max(lc->lazychmax, lazychmax - lc->lazyadd);
                rc->lazychmax = max(rc->lazychmax, lazychmax - rc->lazyadd);
            }
            lazychmax = -INF;
        }
        if (lazyadd) {
            if (l == r) val += lazyadd;
            else {
                lc->lazyadd += lazyadd;
                rc->lazyadd += lazyadd;
            }
            lazyadd = 0;
        }
    }

    void add(int ul, int ur, ll v) {
        clean();
        if (ul > r or ur < l) return;
        if (l >= ul and r <= ur) lazyadd += v;
        else lc->add(ul, ur, v), rc->add(ul, ur, v);
    }

    ll chmax(int i) {
        clean();
        if (l == r) return val;
        int m = (l + r) >> 1;
        if (i <= m) {
            rc->clean();
            return rc->lazychmax = lc->chmax(i);
        } else return rc->chmax(i);
    }
};

int main() {
    cin >> N >> M;
    for (int i = 0; i < N; ++i) {
        cin >> a[i] >> s[i] >> p[i];
        psa[i + 1] = psa[i] + a[i];
    }
    for (int i = 0; i < M; ++i) {
        cin >> b[i] >> t[i] >> q[i];
        psb[i + 1] = psb[i] + b[i];
        auto it = upper_bound(psa, psa + N + 1, t[i] - psb[i + 1]);
        if (it - psa > N) off += q[i];
        else if (it != psa) rem[it - psa].emplace_back(i);
    }
    Node root{0, M};
    for (int i = 1; i <= N; ++i) {
        auto it = upper_bound(psb, psb + M + 1, s[i - 1] - psa[i]);
        if (it != psb) root.add(0, it - psb - 1, p[i - 1]);
        for (int j: rem[i]) root.add(j + 1, M, q[j]);
        for (int j: rem[i]) root.chmax(j);
        if (it != psb) root.chmax(it - psb - 1);
    }
    cout << root.chmax(M) + off;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 476 ms 75608 KB Output is correct
2 Correct 454 ms 75424 KB Output is correct
3 Correct 362 ms 71504 KB Output is correct
4 Correct 439 ms 75660 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 415 ms 72788 KB Output is correct
7 Correct 188 ms 60500 KB Output is correct
8 Correct 195 ms 35668 KB Output is correct
9 Correct 382 ms 72532 KB Output is correct
10 Correct 319 ms 72020 KB Output is correct
11 Correct 278 ms 66156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB Output is correct
2 Correct 11 ms 23864 KB Output is correct
3 Correct 12 ms 23900 KB Output is correct
4 Correct 9 ms 23900 KB Output is correct
5 Correct 9 ms 23900 KB Output is correct
6 Correct 9 ms 23900 KB Output is correct
7 Correct 9 ms 23900 KB Output is correct
8 Correct 9 ms 23924 KB Output is correct
9 Correct 9 ms 23912 KB Output is correct
10 Correct 9 ms 23928 KB Output is correct
11 Correct 10 ms 23900 KB Output is correct
12 Correct 9 ms 23900 KB Output is correct
13 Correct 9 ms 23900 KB Output is correct
14 Correct 9 ms 23900 KB Output is correct
15 Correct 9 ms 23900 KB Output is correct
16 Correct 9 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB Output is correct
2 Correct 11 ms 23864 KB Output is correct
3 Correct 12 ms 23900 KB Output is correct
4 Correct 9 ms 23900 KB Output is correct
5 Correct 9 ms 23900 KB Output is correct
6 Correct 9 ms 23900 KB Output is correct
7 Correct 9 ms 23900 KB Output is correct
8 Correct 9 ms 23924 KB Output is correct
9 Correct 9 ms 23912 KB Output is correct
10 Correct 9 ms 23928 KB Output is correct
11 Correct 10 ms 23900 KB Output is correct
12 Correct 9 ms 23900 KB Output is correct
13 Correct 9 ms 23900 KB Output is correct
14 Correct 9 ms 23900 KB Output is correct
15 Correct 9 ms 23900 KB Output is correct
16 Correct 9 ms 23900 KB Output is correct
17 Correct 14 ms 24212 KB Output is correct
18 Correct 12 ms 24412 KB Output is correct
19 Correct 13 ms 24464 KB Output is correct
20 Correct 14 ms 24412 KB Output is correct
21 Correct 13 ms 24336 KB Output is correct
22 Correct 12 ms 24156 KB Output is correct
23 Correct 12 ms 24156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB Output is correct
2 Correct 11 ms 23864 KB Output is correct
3 Correct 12 ms 23900 KB Output is correct
4 Correct 9 ms 23900 KB Output is correct
5 Correct 9 ms 23900 KB Output is correct
6 Correct 9 ms 23900 KB Output is correct
7 Correct 9 ms 23900 KB Output is correct
8 Correct 9 ms 23924 KB Output is correct
9 Correct 9 ms 23912 KB Output is correct
10 Correct 9 ms 23928 KB Output is correct
11 Correct 10 ms 23900 KB Output is correct
12 Correct 9 ms 23900 KB Output is correct
13 Correct 9 ms 23900 KB Output is correct
14 Correct 9 ms 23900 KB Output is correct
15 Correct 9 ms 23900 KB Output is correct
16 Correct 9 ms 23900 KB Output is correct
17 Correct 14 ms 24212 KB Output is correct
18 Correct 12 ms 24412 KB Output is correct
19 Correct 13 ms 24464 KB Output is correct
20 Correct 14 ms 24412 KB Output is correct
21 Correct 13 ms 24336 KB Output is correct
22 Correct 12 ms 24156 KB Output is correct
23 Correct 12 ms 24156 KB Output is correct
24 Correct 415 ms 68704 KB Output is correct
25 Correct 352 ms 69568 KB Output is correct
26 Correct 390 ms 68944 KB Output is correct
27 Correct 369 ms 75092 KB Output is correct
28 Correct 414 ms 70484 KB Output is correct
29 Correct 336 ms 69460 KB Output is correct
30 Correct 588 ms 72764 KB Output is correct
31 Correct 182 ms 59200 KB Output is correct
32 Correct 152 ms 33872 KB Output is correct
33 Correct 468 ms 70996 KB Output is correct
34 Correct 521 ms 70228 KB Output is correct
35 Correct 465 ms 66384 KB Output is correct
36 Correct 487 ms 66324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB Output is correct
2 Correct 11 ms 23864 KB Output is correct
3 Correct 12 ms 23900 KB Output is correct
4 Correct 9 ms 23900 KB Output is correct
5 Correct 9 ms 23900 KB Output is correct
6 Correct 9 ms 23900 KB Output is correct
7 Correct 9 ms 23900 KB Output is correct
8 Correct 9 ms 23924 KB Output is correct
9 Correct 9 ms 23912 KB Output is correct
10 Correct 9 ms 23928 KB Output is correct
11 Correct 10 ms 23900 KB Output is correct
12 Correct 9 ms 23900 KB Output is correct
13 Correct 9 ms 23900 KB Output is correct
14 Correct 9 ms 23900 KB Output is correct
15 Correct 9 ms 23900 KB Output is correct
16 Correct 9 ms 23900 KB Output is correct
17 Correct 14 ms 24212 KB Output is correct
18 Correct 12 ms 24412 KB Output is correct
19 Correct 13 ms 24464 KB Output is correct
20 Correct 14 ms 24412 KB Output is correct
21 Correct 13 ms 24336 KB Output is correct
22 Correct 12 ms 24156 KB Output is correct
23 Correct 12 ms 24156 KB Output is correct
24 Correct 415 ms 68704 KB Output is correct
25 Correct 352 ms 69568 KB Output is correct
26 Correct 390 ms 68944 KB Output is correct
27 Correct 369 ms 75092 KB Output is correct
28 Correct 414 ms 70484 KB Output is correct
29 Correct 336 ms 69460 KB Output is correct
30 Correct 588 ms 72764 KB Output is correct
31 Correct 182 ms 59200 KB Output is correct
32 Correct 152 ms 33872 KB Output is correct
33 Correct 468 ms 70996 KB Output is correct
34 Correct 521 ms 70228 KB Output is correct
35 Correct 465 ms 66384 KB Output is correct
36 Correct 487 ms 66324 KB Output is correct
37 Correct 401 ms 72020 KB Output is correct
38 Correct 418 ms 78160 KB Output is correct
39 Correct 384 ms 75596 KB Output is correct
40 Correct 407 ms 75600 KB Output is correct
41 Correct 9 ms 23896 KB Output is correct
42 Correct 679 ms 76016 KB Output is correct
43 Correct 533 ms 74204 KB Output is correct
44 Correct 606 ms 72688 KB Output is correct
45 Correct 571 ms 69868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB Output is correct
2 Correct 11 ms 23864 KB Output is correct
3 Correct 12 ms 23900 KB Output is correct
4 Correct 9 ms 23900 KB Output is correct
5 Correct 9 ms 23900 KB Output is correct
6 Correct 9 ms 23900 KB Output is correct
7 Correct 9 ms 23900 KB Output is correct
8 Correct 9 ms 23924 KB Output is correct
9 Correct 9 ms 23912 KB Output is correct
10 Correct 9 ms 23928 KB Output is correct
11 Correct 10 ms 23900 KB Output is correct
12 Correct 9 ms 23900 KB Output is correct
13 Correct 9 ms 23900 KB Output is correct
14 Correct 9 ms 23900 KB Output is correct
15 Correct 9 ms 23900 KB Output is correct
16 Correct 9 ms 23900 KB Output is correct
17 Correct 14 ms 24212 KB Output is correct
18 Correct 12 ms 24412 KB Output is correct
19 Correct 13 ms 24464 KB Output is correct
20 Correct 14 ms 24412 KB Output is correct
21 Correct 13 ms 24336 KB Output is correct
22 Correct 12 ms 24156 KB Output is correct
23 Correct 12 ms 24156 KB Output is correct
24 Correct 415 ms 68704 KB Output is correct
25 Correct 352 ms 69568 KB Output is correct
26 Correct 390 ms 68944 KB Output is correct
27 Correct 369 ms 75092 KB Output is correct
28 Correct 414 ms 70484 KB Output is correct
29 Correct 336 ms 69460 KB Output is correct
30 Correct 588 ms 72764 KB Output is correct
31 Correct 182 ms 59200 KB Output is correct
32 Correct 152 ms 33872 KB Output is correct
33 Correct 468 ms 70996 KB Output is correct
34 Correct 521 ms 70228 KB Output is correct
35 Correct 465 ms 66384 KB Output is correct
36 Correct 487 ms 66324 KB Output is correct
37 Correct 401 ms 72020 KB Output is correct
38 Correct 418 ms 78160 KB Output is correct
39 Correct 384 ms 75596 KB Output is correct
40 Correct 407 ms 75600 KB Output is correct
41 Correct 9 ms 23896 KB Output is correct
42 Correct 679 ms 76016 KB Output is correct
43 Correct 533 ms 74204 KB Output is correct
44 Correct 606 ms 72688 KB Output is correct
45 Correct 571 ms 69868 KB Output is correct
46 Correct 2169 ms 265816 KB Output is correct
47 Correct 2235 ms 297132 KB Output is correct
48 Correct 2191 ms 283520 KB Output is correct
49 Correct 2143 ms 283568 KB Output is correct
50 Correct 4534 ms 285432 KB Output is correct
51 Correct 3062 ms 272980 KB Output is correct
52 Correct 3625 ms 256816 KB Output is correct
53 Correct 3896 ms 253832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 476 ms 75608 KB Output is correct
2 Correct 454 ms 75424 KB Output is correct
3 Correct 362 ms 71504 KB Output is correct
4 Correct 439 ms 75660 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 415 ms 72788 KB Output is correct
7 Correct 188 ms 60500 KB Output is correct
8 Correct 195 ms 35668 KB Output is correct
9 Correct 382 ms 72532 KB Output is correct
10 Correct 319 ms 72020 KB Output is correct
11 Correct 278 ms 66156 KB Output is correct
12 Correct 10 ms 23900 KB Output is correct
13 Correct 11 ms 23864 KB Output is correct
14 Correct 12 ms 23900 KB Output is correct
15 Correct 9 ms 23900 KB Output is correct
16 Correct 9 ms 23900 KB Output is correct
17 Correct 9 ms 23900 KB Output is correct
18 Correct 9 ms 23900 KB Output is correct
19 Correct 9 ms 23924 KB Output is correct
20 Correct 9 ms 23912 KB Output is correct
21 Correct 9 ms 23928 KB Output is correct
22 Correct 10 ms 23900 KB Output is correct
23 Correct 9 ms 23900 KB Output is correct
24 Correct 9 ms 23900 KB Output is correct
25 Correct 9 ms 23900 KB Output is correct
26 Correct 9 ms 23900 KB Output is correct
27 Correct 9 ms 23900 KB Output is correct
28 Correct 14 ms 24212 KB Output is correct
29 Correct 12 ms 24412 KB Output is correct
30 Correct 13 ms 24464 KB Output is correct
31 Correct 14 ms 24412 KB Output is correct
32 Correct 13 ms 24336 KB Output is correct
33 Correct 12 ms 24156 KB Output is correct
34 Correct 12 ms 24156 KB Output is correct
35 Correct 415 ms 68704 KB Output is correct
36 Correct 352 ms 69568 KB Output is correct
37 Correct 390 ms 68944 KB Output is correct
38 Correct 369 ms 75092 KB Output is correct
39 Correct 414 ms 70484 KB Output is correct
40 Correct 336 ms 69460 KB Output is correct
41 Correct 588 ms 72764 KB Output is correct
42 Correct 182 ms 59200 KB Output is correct
43 Correct 152 ms 33872 KB Output is correct
44 Correct 468 ms 70996 KB Output is correct
45 Correct 521 ms 70228 KB Output is correct
46 Correct 465 ms 66384 KB Output is correct
47 Correct 487 ms 66324 KB Output is correct
48 Correct 401 ms 72020 KB Output is correct
49 Correct 418 ms 78160 KB Output is correct
50 Correct 384 ms 75596 KB Output is correct
51 Correct 407 ms 75600 KB Output is correct
52 Correct 9 ms 23896 KB Output is correct
53 Correct 679 ms 76016 KB Output is correct
54 Correct 533 ms 74204 KB Output is correct
55 Correct 606 ms 72688 KB Output is correct
56 Correct 571 ms 69868 KB Output is correct
57 Correct 430 ms 72532 KB Output is correct
58 Correct 434 ms 78636 KB Output is correct
59 Correct 428 ms 76580 KB Output is correct
60 Correct 415 ms 76372 KB Output is correct
61 Correct 610 ms 73044 KB Output is correct
62 Correct 9 ms 23896 KB Output is correct
63 Correct 708 ms 76164 KB Output is correct
64 Correct 530 ms 73040 KB Output is correct
65 Correct 599 ms 74120 KB Output is correct
66 Correct 557 ms 69700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 476 ms 75608 KB Output is correct
2 Correct 454 ms 75424 KB Output is correct
3 Correct 362 ms 71504 KB Output is correct
4 Correct 439 ms 75660 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 415 ms 72788 KB Output is correct
7 Correct 188 ms 60500 KB Output is correct
8 Correct 195 ms 35668 KB Output is correct
9 Correct 382 ms 72532 KB Output is correct
10 Correct 319 ms 72020 KB Output is correct
11 Correct 278 ms 66156 KB Output is correct
12 Correct 10 ms 23900 KB Output is correct
13 Correct 11 ms 23864 KB Output is correct
14 Correct 12 ms 23900 KB Output is correct
15 Correct 9 ms 23900 KB Output is correct
16 Correct 9 ms 23900 KB Output is correct
17 Correct 9 ms 23900 KB Output is correct
18 Correct 9 ms 23900 KB Output is correct
19 Correct 9 ms 23924 KB Output is correct
20 Correct 9 ms 23912 KB Output is correct
21 Correct 9 ms 23928 KB Output is correct
22 Correct 10 ms 23900 KB Output is correct
23 Correct 9 ms 23900 KB Output is correct
24 Correct 9 ms 23900 KB Output is correct
25 Correct 9 ms 23900 KB Output is correct
26 Correct 9 ms 23900 KB Output is correct
27 Correct 9 ms 23900 KB Output is correct
28 Correct 14 ms 24212 KB Output is correct
29 Correct 12 ms 24412 KB Output is correct
30 Correct 13 ms 24464 KB Output is correct
31 Correct 14 ms 24412 KB Output is correct
32 Correct 13 ms 24336 KB Output is correct
33 Correct 12 ms 24156 KB Output is correct
34 Correct 12 ms 24156 KB Output is correct
35 Correct 415 ms 68704 KB Output is correct
36 Correct 352 ms 69568 KB Output is correct
37 Correct 390 ms 68944 KB Output is correct
38 Correct 369 ms 75092 KB Output is correct
39 Correct 414 ms 70484 KB Output is correct
40 Correct 336 ms 69460 KB Output is correct
41 Correct 588 ms 72764 KB Output is correct
42 Correct 182 ms 59200 KB Output is correct
43 Correct 152 ms 33872 KB Output is correct
44 Correct 468 ms 70996 KB Output is correct
45 Correct 521 ms 70228 KB Output is correct
46 Correct 465 ms 66384 KB Output is correct
47 Correct 487 ms 66324 KB Output is correct
48 Correct 401 ms 72020 KB Output is correct
49 Correct 418 ms 78160 KB Output is correct
50 Correct 384 ms 75596 KB Output is correct
51 Correct 407 ms 75600 KB Output is correct
52 Correct 9 ms 23896 KB Output is correct
53 Correct 679 ms 76016 KB Output is correct
54 Correct 533 ms 74204 KB Output is correct
55 Correct 606 ms 72688 KB Output is correct
56 Correct 571 ms 69868 KB Output is correct
57 Correct 2169 ms 265816 KB Output is correct
58 Correct 2235 ms 297132 KB Output is correct
59 Correct 2191 ms 283520 KB Output is correct
60 Correct 2143 ms 283568 KB Output is correct
61 Correct 4534 ms 285432 KB Output is correct
62 Correct 3062 ms 272980 KB Output is correct
63 Correct 3625 ms 256816 KB Output is correct
64 Correct 3896 ms 253832 KB Output is correct
65 Correct 430 ms 72532 KB Output is correct
66 Correct 434 ms 78636 KB Output is correct
67 Correct 428 ms 76580 KB Output is correct
68 Correct 415 ms 76372 KB Output is correct
69 Correct 610 ms 73044 KB Output is correct
70 Correct 9 ms 23896 KB Output is correct
71 Correct 708 ms 76164 KB Output is correct
72 Correct 530 ms 73040 KB Output is correct
73 Correct 599 ms 74120 KB Output is correct
74 Correct 557 ms 69700 KB Output is correct
75 Correct 2161 ms 267604 KB Output is correct
76 Correct 2263 ms 298964 KB Output is correct
77 Correct 2124 ms 285912 KB Output is correct
78 Correct 2109 ms 285948 KB Output is correct
79 Correct 4706 ms 286100 KB Output is correct
80 Correct 3208 ms 265452 KB Output is correct
81 Correct 3651 ms 270476 KB Output is correct
82 Correct 3956 ms 253700 KB Output is correct
83 Correct 4138 ms 273532 KB Output is correct