답안 #525743

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
525743 2022-02-12T18:47:06 Z two_sides Two Dishes (JOI19_dishes) C++17
74 / 100
3641 ms 223952 KB
#include <bits/stdc++.h>

using namespace std;

#define il i * 2
#define ir i * 2 + 1

using ll = long long;

const int N = 1000005;

ll a[N], b[N], sa[N], sb[N], ca[N], cb[N];
vector<int> pos[N];
ll val[N * 4], tag[N * 4], res;
int lo, hi, n, m, far[N];

void apply(int i, ll v) {
    val[i] += v; tag[i] += v;
}

void push(int i) {
    apply(il, tag[i]);
    apply(ir, tag[i]);
    tag[i] = 0;
}

void add(int i, int l, int r, ll v) {
    if (l >= lo && r <= hi)
        return apply(i, v);
    int m = (l + r) / 2; push(i);
    if (m >= lo) add(il, l, m, v);
    if (m < hi) add(ir, m + 1, r, v);
    val[i] = max(val[il], val[ir]);
}

void assign(int i, int l, int r, ll v) {
    if (l == r) {
        val[i] = v; return;
    }
    int m = (l + r) / 2; push(i);
    if (m >= lo) assign(il, l, m, v);
    else assign(ir, m + 1, r, v);
    val[i] = max(val[il], val[ir]);
}

void get(int i, int l, int r) {
    if (l >= lo && r <= hi) {
        res = max(res, val[i]); return;
    }
    int m = (l + r) / 2; push(i);
    if (m >= lo) get(il, l, m);
    if (m < hi) get(ir, m + 1, r);
}

void add(int l, int r, ll v) {
    lo = l; hi = r; add(1, 0, m, v);
}

void assign(int p, ll v) {
    lo = p; assign(1, 0, m, v);
}

ll get(int l, int r) {
    lo = l; hi = r; res = 0;
    get(1, 0, m); return res;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> sa[i] >> ca[i];
        a[i] += a[i - 1];
    }
    for (int i = 1; i <= m; i++) {
        cin >> b[i] >> sb[i] >> cb[i];
        b[i] += b[i - 1];
    }
    for (int i = 1; i <= m; i++) {
        int x = -1, y = n;
        while (x < y) {
            int z = (x + y + 1) / 2;
            if (b[i] + a[z] <= sb[i]) x = z;
            else y = z - 1;
        }
        if (x >= 0) pos[x].push_back(i);
        
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        int x = -1, y = m;
        while (x < y) {
            int z = (x + y + 1) / 2;
            if (a[i] + b[z] <= sa[i]) x = z;
            else y = z - 1;
        }
        if ((far[i] = x) >= 0) ans += ca[i];
    }
    memset(val, 0xc0, sizeof val);
    assign(0, 0);
    for (int i = 0; i <= n; i++) {
        if (i < n && far[i + 1] >= 0 && far[i + 1] < m) {
            ll v = get(0, far[i + 1] + 1);
            assign(far[i + 1] + 1, v);
        }
        for (int k : pos[i]) {
            ll v = get(0, k); assign(k, v);
        }
        if (i < n && far[i + 1] >= 0 && far[i + 1] < m)
            add(far[i + 1] + 1, m, -ca[i + 1]);
        for (int k : pos[i]) add(k, m, cb[k]);
    }
    cout << val[1] + ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 378 ms 86360 KB Output is correct
2 Correct 355 ms 86712 KB Output is correct
3 Correct 267 ms 83732 KB Output is correct
4 Correct 316 ms 85088 KB Output is correct
5 Correct 26 ms 55116 KB Output is correct
6 Correct 327 ms 85500 KB Output is correct
7 Correct 181 ms 71240 KB Output is correct
8 Correct 103 ms 67584 KB Output is correct
9 Correct 291 ms 84656 KB Output is correct
10 Correct 353 ms 83168 KB Output is correct
11 Correct 228 ms 78128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 55116 KB Output is correct
2 Correct 26 ms 55276 KB Output is correct
3 Correct 24 ms 55072 KB Output is correct
4 Correct 25 ms 55032 KB Output is correct
5 Correct 24 ms 55168 KB Output is correct
6 Correct 29 ms 55112 KB Output is correct
7 Correct 23 ms 55032 KB Output is correct
8 Correct 23 ms 55128 KB Output is correct
9 Correct 24 ms 55108 KB Output is correct
10 Correct 22 ms 55116 KB Output is correct
11 Correct 23 ms 55116 KB Output is correct
12 Correct 24 ms 55104 KB Output is correct
13 Correct 23 ms 55092 KB Output is correct
14 Correct 24 ms 55116 KB Output is correct
15 Correct 24 ms 55108 KB Output is correct
16 Correct 24 ms 55080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 55116 KB Output is correct
2 Correct 26 ms 55276 KB Output is correct
3 Correct 24 ms 55072 KB Output is correct
4 Correct 25 ms 55032 KB Output is correct
5 Correct 24 ms 55168 KB Output is correct
6 Correct 29 ms 55112 KB Output is correct
7 Correct 23 ms 55032 KB Output is correct
8 Correct 23 ms 55128 KB Output is correct
9 Correct 24 ms 55108 KB Output is correct
10 Correct 22 ms 55116 KB Output is correct
11 Correct 23 ms 55116 KB Output is correct
12 Correct 24 ms 55104 KB Output is correct
13 Correct 23 ms 55092 KB Output is correct
14 Correct 24 ms 55116 KB Output is correct
15 Correct 24 ms 55108 KB Output is correct
16 Correct 24 ms 55080 KB Output is correct
17 Correct 25 ms 55408 KB Output is correct
18 Correct 32 ms 55364 KB Output is correct
19 Correct 28 ms 55308 KB Output is correct
20 Correct 29 ms 55456 KB Output is correct
21 Correct 32 ms 55308 KB Output is correct
22 Correct 29 ms 55360 KB Output is correct
23 Correct 27 ms 55364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 55116 KB Output is correct
2 Correct 26 ms 55276 KB Output is correct
3 Correct 24 ms 55072 KB Output is correct
4 Correct 25 ms 55032 KB Output is correct
5 Correct 24 ms 55168 KB Output is correct
6 Correct 29 ms 55112 KB Output is correct
7 Correct 23 ms 55032 KB Output is correct
8 Correct 23 ms 55128 KB Output is correct
9 Correct 24 ms 55108 KB Output is correct
10 Correct 22 ms 55116 KB Output is correct
11 Correct 23 ms 55116 KB Output is correct
12 Correct 24 ms 55104 KB Output is correct
13 Correct 23 ms 55092 KB Output is correct
14 Correct 24 ms 55116 KB Output is correct
15 Correct 24 ms 55108 KB Output is correct
16 Correct 24 ms 55080 KB Output is correct
17 Correct 25 ms 55408 KB Output is correct
18 Correct 32 ms 55364 KB Output is correct
19 Correct 28 ms 55308 KB Output is correct
20 Correct 29 ms 55456 KB Output is correct
21 Correct 32 ms 55308 KB Output is correct
22 Correct 29 ms 55360 KB Output is correct
23 Correct 27 ms 55364 KB Output is correct
24 Correct 326 ms 80452 KB Output is correct
25 Correct 241 ms 80892 KB Output is correct
26 Correct 286 ms 80608 KB Output is correct
27 Correct 273 ms 86264 KB Output is correct
28 Correct 327 ms 82140 KB Output is correct
29 Correct 253 ms 81556 KB Output is correct
30 Correct 518 ms 84044 KB Output is correct
31 Correct 184 ms 70036 KB Output is correct
32 Correct 87 ms 65760 KB Output is correct
33 Correct 332 ms 82068 KB Output is correct
34 Correct 430 ms 82532 KB Output is correct
35 Correct 505 ms 77652 KB Output is correct
36 Correct 495 ms 77620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 55116 KB Output is correct
2 Correct 26 ms 55276 KB Output is correct
3 Correct 24 ms 55072 KB Output is correct
4 Correct 25 ms 55032 KB Output is correct
5 Correct 24 ms 55168 KB Output is correct
6 Correct 29 ms 55112 KB Output is correct
7 Correct 23 ms 55032 KB Output is correct
8 Correct 23 ms 55128 KB Output is correct
9 Correct 24 ms 55108 KB Output is correct
10 Correct 22 ms 55116 KB Output is correct
11 Correct 23 ms 55116 KB Output is correct
12 Correct 24 ms 55104 KB Output is correct
13 Correct 23 ms 55092 KB Output is correct
14 Correct 24 ms 55116 KB Output is correct
15 Correct 24 ms 55108 KB Output is correct
16 Correct 24 ms 55080 KB Output is correct
17 Correct 25 ms 55408 KB Output is correct
18 Correct 32 ms 55364 KB Output is correct
19 Correct 28 ms 55308 KB Output is correct
20 Correct 29 ms 55456 KB Output is correct
21 Correct 32 ms 55308 KB Output is correct
22 Correct 29 ms 55360 KB Output is correct
23 Correct 27 ms 55364 KB Output is correct
24 Correct 326 ms 80452 KB Output is correct
25 Correct 241 ms 80892 KB Output is correct
26 Correct 286 ms 80608 KB Output is correct
27 Correct 273 ms 86264 KB Output is correct
28 Correct 327 ms 82140 KB Output is correct
29 Correct 253 ms 81556 KB Output is correct
30 Correct 518 ms 84044 KB Output is correct
31 Correct 184 ms 70036 KB Output is correct
32 Correct 87 ms 65760 KB Output is correct
33 Correct 332 ms 82068 KB Output is correct
34 Correct 430 ms 82532 KB Output is correct
35 Correct 505 ms 77652 KB Output is correct
36 Correct 495 ms 77620 KB Output is correct
37 Correct 314 ms 83632 KB Output is correct
38 Correct 284 ms 89416 KB Output is correct
39 Correct 339 ms 86616 KB Output is correct
40 Correct 344 ms 86636 KB Output is correct
41 Correct 23 ms 55236 KB Output is correct
42 Correct 588 ms 87020 KB Output is correct
43 Correct 383 ms 84960 KB Output is correct
44 Correct 450 ms 85316 KB Output is correct
45 Correct 486 ms 80700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 55116 KB Output is correct
2 Correct 26 ms 55276 KB Output is correct
3 Correct 24 ms 55072 KB Output is correct
4 Correct 25 ms 55032 KB Output is correct
5 Correct 24 ms 55168 KB Output is correct
6 Correct 29 ms 55112 KB Output is correct
7 Correct 23 ms 55032 KB Output is correct
8 Correct 23 ms 55128 KB Output is correct
9 Correct 24 ms 55108 KB Output is correct
10 Correct 22 ms 55116 KB Output is correct
11 Correct 23 ms 55116 KB Output is correct
12 Correct 24 ms 55104 KB Output is correct
13 Correct 23 ms 55092 KB Output is correct
14 Correct 24 ms 55116 KB Output is correct
15 Correct 24 ms 55108 KB Output is correct
16 Correct 24 ms 55080 KB Output is correct
17 Correct 25 ms 55408 KB Output is correct
18 Correct 32 ms 55364 KB Output is correct
19 Correct 28 ms 55308 KB Output is correct
20 Correct 29 ms 55456 KB Output is correct
21 Correct 32 ms 55308 KB Output is correct
22 Correct 29 ms 55360 KB Output is correct
23 Correct 27 ms 55364 KB Output is correct
24 Correct 326 ms 80452 KB Output is correct
25 Correct 241 ms 80892 KB Output is correct
26 Correct 286 ms 80608 KB Output is correct
27 Correct 273 ms 86264 KB Output is correct
28 Correct 327 ms 82140 KB Output is correct
29 Correct 253 ms 81556 KB Output is correct
30 Correct 518 ms 84044 KB Output is correct
31 Correct 184 ms 70036 KB Output is correct
32 Correct 87 ms 65760 KB Output is correct
33 Correct 332 ms 82068 KB Output is correct
34 Correct 430 ms 82532 KB Output is correct
35 Correct 505 ms 77652 KB Output is correct
36 Correct 495 ms 77620 KB Output is correct
37 Correct 314 ms 83632 KB Output is correct
38 Correct 284 ms 89416 KB Output is correct
39 Correct 339 ms 86616 KB Output is correct
40 Correct 344 ms 86636 KB Output is correct
41 Correct 23 ms 55236 KB Output is correct
42 Correct 588 ms 87020 KB Output is correct
43 Correct 383 ms 84960 KB Output is correct
44 Correct 450 ms 85316 KB Output is correct
45 Correct 486 ms 80700 KB Output is correct
46 Correct 1535 ms 194344 KB Output is correct
47 Correct 1353 ms 223952 KB Output is correct
48 Correct 1774 ms 209996 KB Output is correct
49 Correct 1737 ms 210028 KB Output is correct
50 Correct 3641 ms 212052 KB Output is correct
51 Correct 1980 ms 199244 KB Output is correct
52 Correct 2403 ms 198680 KB Output is correct
53 Correct 2945 ms 180600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 378 ms 86360 KB Output is correct
2 Correct 355 ms 86712 KB Output is correct
3 Correct 267 ms 83732 KB Output is correct
4 Correct 316 ms 85088 KB Output is correct
5 Correct 26 ms 55116 KB Output is correct
6 Correct 327 ms 85500 KB Output is correct
7 Correct 181 ms 71240 KB Output is correct
8 Correct 103 ms 67584 KB Output is correct
9 Correct 291 ms 84656 KB Output is correct
10 Correct 353 ms 83168 KB Output is correct
11 Correct 228 ms 78128 KB Output is correct
12 Correct 25 ms 55116 KB Output is correct
13 Correct 26 ms 55276 KB Output is correct
14 Correct 24 ms 55072 KB Output is correct
15 Correct 25 ms 55032 KB Output is correct
16 Correct 24 ms 55168 KB Output is correct
17 Correct 29 ms 55112 KB Output is correct
18 Correct 23 ms 55032 KB Output is correct
19 Correct 23 ms 55128 KB Output is correct
20 Correct 24 ms 55108 KB Output is correct
21 Correct 22 ms 55116 KB Output is correct
22 Correct 23 ms 55116 KB Output is correct
23 Correct 24 ms 55104 KB Output is correct
24 Correct 23 ms 55092 KB Output is correct
25 Correct 24 ms 55116 KB Output is correct
26 Correct 24 ms 55108 KB Output is correct
27 Correct 24 ms 55080 KB Output is correct
28 Correct 25 ms 55408 KB Output is correct
29 Correct 32 ms 55364 KB Output is correct
30 Correct 28 ms 55308 KB Output is correct
31 Correct 29 ms 55456 KB Output is correct
32 Correct 32 ms 55308 KB Output is correct
33 Correct 29 ms 55360 KB Output is correct
34 Correct 27 ms 55364 KB Output is correct
35 Correct 326 ms 80452 KB Output is correct
36 Correct 241 ms 80892 KB Output is correct
37 Correct 286 ms 80608 KB Output is correct
38 Correct 273 ms 86264 KB Output is correct
39 Correct 327 ms 82140 KB Output is correct
40 Correct 253 ms 81556 KB Output is correct
41 Correct 518 ms 84044 KB Output is correct
42 Correct 184 ms 70036 KB Output is correct
43 Correct 87 ms 65760 KB Output is correct
44 Correct 332 ms 82068 KB Output is correct
45 Correct 430 ms 82532 KB Output is correct
46 Correct 505 ms 77652 KB Output is correct
47 Correct 495 ms 77620 KB Output is correct
48 Correct 314 ms 83632 KB Output is correct
49 Correct 284 ms 89416 KB Output is correct
50 Correct 339 ms 86616 KB Output is correct
51 Correct 344 ms 86636 KB Output is correct
52 Correct 23 ms 55236 KB Output is correct
53 Correct 588 ms 87020 KB Output is correct
54 Correct 383 ms 84960 KB Output is correct
55 Correct 450 ms 85316 KB Output is correct
56 Correct 486 ms 80700 KB Output is correct
57 Incorrect 319 ms 84064 KB Output isn't correct
58 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 378 ms 86360 KB Output is correct
2 Correct 355 ms 86712 KB Output is correct
3 Correct 267 ms 83732 KB Output is correct
4 Correct 316 ms 85088 KB Output is correct
5 Correct 26 ms 55116 KB Output is correct
6 Correct 327 ms 85500 KB Output is correct
7 Correct 181 ms 71240 KB Output is correct
8 Correct 103 ms 67584 KB Output is correct
9 Correct 291 ms 84656 KB Output is correct
10 Correct 353 ms 83168 KB Output is correct
11 Correct 228 ms 78128 KB Output is correct
12 Correct 25 ms 55116 KB Output is correct
13 Correct 26 ms 55276 KB Output is correct
14 Correct 24 ms 55072 KB Output is correct
15 Correct 25 ms 55032 KB Output is correct
16 Correct 24 ms 55168 KB Output is correct
17 Correct 29 ms 55112 KB Output is correct
18 Correct 23 ms 55032 KB Output is correct
19 Correct 23 ms 55128 KB Output is correct
20 Correct 24 ms 55108 KB Output is correct
21 Correct 22 ms 55116 KB Output is correct
22 Correct 23 ms 55116 KB Output is correct
23 Correct 24 ms 55104 KB Output is correct
24 Correct 23 ms 55092 KB Output is correct
25 Correct 24 ms 55116 KB Output is correct
26 Correct 24 ms 55108 KB Output is correct
27 Correct 24 ms 55080 KB Output is correct
28 Correct 25 ms 55408 KB Output is correct
29 Correct 32 ms 55364 KB Output is correct
30 Correct 28 ms 55308 KB Output is correct
31 Correct 29 ms 55456 KB Output is correct
32 Correct 32 ms 55308 KB Output is correct
33 Correct 29 ms 55360 KB Output is correct
34 Correct 27 ms 55364 KB Output is correct
35 Correct 326 ms 80452 KB Output is correct
36 Correct 241 ms 80892 KB Output is correct
37 Correct 286 ms 80608 KB Output is correct
38 Correct 273 ms 86264 KB Output is correct
39 Correct 327 ms 82140 KB Output is correct
40 Correct 253 ms 81556 KB Output is correct
41 Correct 518 ms 84044 KB Output is correct
42 Correct 184 ms 70036 KB Output is correct
43 Correct 87 ms 65760 KB Output is correct
44 Correct 332 ms 82068 KB Output is correct
45 Correct 430 ms 82532 KB Output is correct
46 Correct 505 ms 77652 KB Output is correct
47 Correct 495 ms 77620 KB Output is correct
48 Correct 314 ms 83632 KB Output is correct
49 Correct 284 ms 89416 KB Output is correct
50 Correct 339 ms 86616 KB Output is correct
51 Correct 344 ms 86636 KB Output is correct
52 Correct 23 ms 55236 KB Output is correct
53 Correct 588 ms 87020 KB Output is correct
54 Correct 383 ms 84960 KB Output is correct
55 Correct 450 ms 85316 KB Output is correct
56 Correct 486 ms 80700 KB Output is correct
57 Correct 1535 ms 194344 KB Output is correct
58 Correct 1353 ms 223952 KB Output is correct
59 Correct 1774 ms 209996 KB Output is correct
60 Correct 1737 ms 210028 KB Output is correct
61 Correct 3641 ms 212052 KB Output is correct
62 Correct 1980 ms 199244 KB Output is correct
63 Correct 2403 ms 198680 KB Output is correct
64 Correct 2945 ms 180600 KB Output is correct
65 Incorrect 319 ms 84064 KB Output isn't correct
66 Halted 0 ms 0 KB -