Submission #526050

# Submission time Handle Problem Language Result Execution time Memory
526050 2022-02-13T15:49:32 Z two_sides Two Dishes (JOI19_dishes) C++17
100 / 100
3349 ms 225548 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 = -1e18;
    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) assign(m, val[1]);
        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 << get(m, m) + ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 353 ms 86292 KB Output is correct
2 Correct 355 ms 86740 KB Output is correct
3 Correct 264 ms 83600 KB Output is correct
4 Correct 291 ms 85104 KB Output is correct
5 Correct 23 ms 55108 KB Output is correct
6 Correct 334 ms 85492 KB Output is correct
7 Correct 182 ms 71144 KB Output is correct
8 Correct 99 ms 67576 KB Output is correct
9 Correct 264 ms 84796 KB Output is correct
10 Correct 331 ms 83108 KB Output is correct
11 Correct 221 ms 78104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 55028 KB Output is correct
2 Correct 24 ms 55148 KB Output is correct
3 Correct 25 ms 55036 KB Output is correct
4 Correct 24 ms 55032 KB Output is correct
5 Correct 24 ms 55116 KB Output is correct
6 Correct 24 ms 55168 KB Output is correct
7 Correct 24 ms 55132 KB Output is correct
8 Correct 24 ms 55032 KB Output is correct
9 Correct 24 ms 55040 KB Output is correct
10 Correct 24 ms 55116 KB Output is correct
11 Correct 24 ms 55068 KB Output is correct
12 Correct 23 ms 55096 KB Output is correct
13 Correct 25 ms 55116 KB Output is correct
14 Correct 24 ms 55048 KB Output is correct
15 Correct 23 ms 55060 KB Output is correct
16 Correct 24 ms 55164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 55028 KB Output is correct
2 Correct 24 ms 55148 KB Output is correct
3 Correct 25 ms 55036 KB Output is correct
4 Correct 24 ms 55032 KB Output is correct
5 Correct 24 ms 55116 KB Output is correct
6 Correct 24 ms 55168 KB Output is correct
7 Correct 24 ms 55132 KB Output is correct
8 Correct 24 ms 55032 KB Output is correct
9 Correct 24 ms 55040 KB Output is correct
10 Correct 24 ms 55116 KB Output is correct
11 Correct 24 ms 55068 KB Output is correct
12 Correct 23 ms 55096 KB Output is correct
13 Correct 25 ms 55116 KB Output is correct
14 Correct 24 ms 55048 KB Output is correct
15 Correct 23 ms 55060 KB Output is correct
16 Correct 24 ms 55164 KB Output is correct
17 Correct 26 ms 55360 KB Output is correct
18 Correct 26 ms 55312 KB Output is correct
19 Correct 26 ms 55364 KB Output is correct
20 Correct 26 ms 55372 KB Output is correct
21 Correct 27 ms 55304 KB Output is correct
22 Correct 28 ms 55288 KB Output is correct
23 Correct 27 ms 55372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 55028 KB Output is correct
2 Correct 24 ms 55148 KB Output is correct
3 Correct 25 ms 55036 KB Output is correct
4 Correct 24 ms 55032 KB Output is correct
5 Correct 24 ms 55116 KB Output is correct
6 Correct 24 ms 55168 KB Output is correct
7 Correct 24 ms 55132 KB Output is correct
8 Correct 24 ms 55032 KB Output is correct
9 Correct 24 ms 55040 KB Output is correct
10 Correct 24 ms 55116 KB Output is correct
11 Correct 24 ms 55068 KB Output is correct
12 Correct 23 ms 55096 KB Output is correct
13 Correct 25 ms 55116 KB Output is correct
14 Correct 24 ms 55048 KB Output is correct
15 Correct 23 ms 55060 KB Output is correct
16 Correct 24 ms 55164 KB Output is correct
17 Correct 26 ms 55360 KB Output is correct
18 Correct 26 ms 55312 KB Output is correct
19 Correct 26 ms 55364 KB Output is correct
20 Correct 26 ms 55372 KB Output is correct
21 Correct 27 ms 55304 KB Output is correct
22 Correct 28 ms 55288 KB Output is correct
23 Correct 27 ms 55372 KB Output is correct
24 Correct 301 ms 80472 KB Output is correct
25 Correct 257 ms 80836 KB Output is correct
26 Correct 301 ms 80516 KB Output is correct
27 Correct 297 ms 86480 KB Output is correct
28 Correct 332 ms 81972 KB Output is correct
29 Correct 255 ms 81608 KB Output is correct
30 Correct 594 ms 84020 KB Output is correct
31 Correct 205 ms 70084 KB Output is correct
32 Correct 89 ms 65824 KB Output is correct
33 Correct 399 ms 82040 KB Output is correct
34 Correct 531 ms 82480 KB Output is correct
35 Correct 536 ms 77580 KB Output is correct
36 Correct 531 ms 77564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 55028 KB Output is correct
2 Correct 24 ms 55148 KB Output is correct
3 Correct 25 ms 55036 KB Output is correct
4 Correct 24 ms 55032 KB Output is correct
5 Correct 24 ms 55116 KB Output is correct
6 Correct 24 ms 55168 KB Output is correct
7 Correct 24 ms 55132 KB Output is correct
8 Correct 24 ms 55032 KB Output is correct
9 Correct 24 ms 55040 KB Output is correct
10 Correct 24 ms 55116 KB Output is correct
11 Correct 24 ms 55068 KB Output is correct
12 Correct 23 ms 55096 KB Output is correct
13 Correct 25 ms 55116 KB Output is correct
14 Correct 24 ms 55048 KB Output is correct
15 Correct 23 ms 55060 KB Output is correct
16 Correct 24 ms 55164 KB Output is correct
17 Correct 26 ms 55360 KB Output is correct
18 Correct 26 ms 55312 KB Output is correct
19 Correct 26 ms 55364 KB Output is correct
20 Correct 26 ms 55372 KB Output is correct
21 Correct 27 ms 55304 KB Output is correct
22 Correct 28 ms 55288 KB Output is correct
23 Correct 27 ms 55372 KB Output is correct
24 Correct 301 ms 80472 KB Output is correct
25 Correct 257 ms 80836 KB Output is correct
26 Correct 301 ms 80516 KB Output is correct
27 Correct 297 ms 86480 KB Output is correct
28 Correct 332 ms 81972 KB Output is correct
29 Correct 255 ms 81608 KB Output is correct
30 Correct 594 ms 84020 KB Output is correct
31 Correct 205 ms 70084 KB Output is correct
32 Correct 89 ms 65824 KB Output is correct
33 Correct 399 ms 82040 KB Output is correct
34 Correct 531 ms 82480 KB Output is correct
35 Correct 536 ms 77580 KB Output is correct
36 Correct 531 ms 77564 KB Output is correct
37 Correct 349 ms 83600 KB Output is correct
38 Correct 322 ms 89292 KB Output is correct
39 Correct 377 ms 86660 KB Output is correct
40 Correct 361 ms 86692 KB Output is correct
41 Correct 26 ms 55108 KB Output is correct
42 Correct 556 ms 87296 KB Output is correct
43 Correct 368 ms 85156 KB Output is correct
44 Correct 475 ms 85384 KB Output is correct
45 Correct 513 ms 80756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 55028 KB Output is correct
2 Correct 24 ms 55148 KB Output is correct
3 Correct 25 ms 55036 KB Output is correct
4 Correct 24 ms 55032 KB Output is correct
5 Correct 24 ms 55116 KB Output is correct
6 Correct 24 ms 55168 KB Output is correct
7 Correct 24 ms 55132 KB Output is correct
8 Correct 24 ms 55032 KB Output is correct
9 Correct 24 ms 55040 KB Output is correct
10 Correct 24 ms 55116 KB Output is correct
11 Correct 24 ms 55068 KB Output is correct
12 Correct 23 ms 55096 KB Output is correct
13 Correct 25 ms 55116 KB Output is correct
14 Correct 24 ms 55048 KB Output is correct
15 Correct 23 ms 55060 KB Output is correct
16 Correct 24 ms 55164 KB Output is correct
17 Correct 26 ms 55360 KB Output is correct
18 Correct 26 ms 55312 KB Output is correct
19 Correct 26 ms 55364 KB Output is correct
20 Correct 26 ms 55372 KB Output is correct
21 Correct 27 ms 55304 KB Output is correct
22 Correct 28 ms 55288 KB Output is correct
23 Correct 27 ms 55372 KB Output is correct
24 Correct 301 ms 80472 KB Output is correct
25 Correct 257 ms 80836 KB Output is correct
26 Correct 301 ms 80516 KB Output is correct
27 Correct 297 ms 86480 KB Output is correct
28 Correct 332 ms 81972 KB Output is correct
29 Correct 255 ms 81608 KB Output is correct
30 Correct 594 ms 84020 KB Output is correct
31 Correct 205 ms 70084 KB Output is correct
32 Correct 89 ms 65824 KB Output is correct
33 Correct 399 ms 82040 KB Output is correct
34 Correct 531 ms 82480 KB Output is correct
35 Correct 536 ms 77580 KB Output is correct
36 Correct 531 ms 77564 KB Output is correct
37 Correct 349 ms 83600 KB Output is correct
38 Correct 322 ms 89292 KB Output is correct
39 Correct 377 ms 86660 KB Output is correct
40 Correct 361 ms 86692 KB Output is correct
41 Correct 26 ms 55108 KB Output is correct
42 Correct 556 ms 87296 KB Output is correct
43 Correct 368 ms 85156 KB Output is correct
44 Correct 475 ms 85384 KB Output is correct
45 Correct 513 ms 80756 KB Output is correct
46 Correct 1589 ms 173788 KB Output is correct
47 Correct 1388 ms 202988 KB Output is correct
48 Correct 1803 ms 203184 KB Output is correct
49 Correct 1795 ms 203328 KB Output is correct
50 Correct 3325 ms 191176 KB Output is correct
51 Correct 2090 ms 179272 KB Output is correct
52 Correct 2523 ms 178656 KB Output is correct
53 Correct 3084 ms 180368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 353 ms 86292 KB Output is correct
2 Correct 355 ms 86740 KB Output is correct
3 Correct 264 ms 83600 KB Output is correct
4 Correct 291 ms 85104 KB Output is correct
5 Correct 23 ms 55108 KB Output is correct
6 Correct 334 ms 85492 KB Output is correct
7 Correct 182 ms 71144 KB Output is correct
8 Correct 99 ms 67576 KB Output is correct
9 Correct 264 ms 84796 KB Output is correct
10 Correct 331 ms 83108 KB Output is correct
11 Correct 221 ms 78104 KB Output is correct
12 Correct 27 ms 55028 KB Output is correct
13 Correct 24 ms 55148 KB Output is correct
14 Correct 25 ms 55036 KB Output is correct
15 Correct 24 ms 55032 KB Output is correct
16 Correct 24 ms 55116 KB Output is correct
17 Correct 24 ms 55168 KB Output is correct
18 Correct 24 ms 55132 KB Output is correct
19 Correct 24 ms 55032 KB Output is correct
20 Correct 24 ms 55040 KB Output is correct
21 Correct 24 ms 55116 KB Output is correct
22 Correct 24 ms 55068 KB Output is correct
23 Correct 23 ms 55096 KB Output is correct
24 Correct 25 ms 55116 KB Output is correct
25 Correct 24 ms 55048 KB Output is correct
26 Correct 23 ms 55060 KB Output is correct
27 Correct 24 ms 55164 KB Output is correct
28 Correct 26 ms 55360 KB Output is correct
29 Correct 26 ms 55312 KB Output is correct
30 Correct 26 ms 55364 KB Output is correct
31 Correct 26 ms 55372 KB Output is correct
32 Correct 27 ms 55304 KB Output is correct
33 Correct 28 ms 55288 KB Output is correct
34 Correct 27 ms 55372 KB Output is correct
35 Correct 301 ms 80472 KB Output is correct
36 Correct 257 ms 80836 KB Output is correct
37 Correct 301 ms 80516 KB Output is correct
38 Correct 297 ms 86480 KB Output is correct
39 Correct 332 ms 81972 KB Output is correct
40 Correct 255 ms 81608 KB Output is correct
41 Correct 594 ms 84020 KB Output is correct
42 Correct 205 ms 70084 KB Output is correct
43 Correct 89 ms 65824 KB Output is correct
44 Correct 399 ms 82040 KB Output is correct
45 Correct 531 ms 82480 KB Output is correct
46 Correct 536 ms 77580 KB Output is correct
47 Correct 531 ms 77564 KB Output is correct
48 Correct 349 ms 83600 KB Output is correct
49 Correct 322 ms 89292 KB Output is correct
50 Correct 377 ms 86660 KB Output is correct
51 Correct 361 ms 86692 KB Output is correct
52 Correct 26 ms 55108 KB Output is correct
53 Correct 556 ms 87296 KB Output is correct
54 Correct 368 ms 85156 KB Output is correct
55 Correct 475 ms 85384 KB Output is correct
56 Correct 513 ms 80756 KB Output is correct
57 Correct 321 ms 84020 KB Output is correct
58 Correct 290 ms 89772 KB Output is correct
59 Correct 358 ms 87684 KB Output is correct
60 Correct 361 ms 87616 KB Output is correct
61 Correct 547 ms 84136 KB Output is correct
62 Correct 24 ms 55048 KB Output is correct
63 Correct 553 ms 87244 KB Output is correct
64 Correct 366 ms 85108 KB Output is correct
65 Correct 461 ms 85248 KB Output is correct
66 Correct 489 ms 80760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 353 ms 86292 KB Output is correct
2 Correct 355 ms 86740 KB Output is correct
3 Correct 264 ms 83600 KB Output is correct
4 Correct 291 ms 85104 KB Output is correct
5 Correct 23 ms 55108 KB Output is correct
6 Correct 334 ms 85492 KB Output is correct
7 Correct 182 ms 71144 KB Output is correct
8 Correct 99 ms 67576 KB Output is correct
9 Correct 264 ms 84796 KB Output is correct
10 Correct 331 ms 83108 KB Output is correct
11 Correct 221 ms 78104 KB Output is correct
12 Correct 27 ms 55028 KB Output is correct
13 Correct 24 ms 55148 KB Output is correct
14 Correct 25 ms 55036 KB Output is correct
15 Correct 24 ms 55032 KB Output is correct
16 Correct 24 ms 55116 KB Output is correct
17 Correct 24 ms 55168 KB Output is correct
18 Correct 24 ms 55132 KB Output is correct
19 Correct 24 ms 55032 KB Output is correct
20 Correct 24 ms 55040 KB Output is correct
21 Correct 24 ms 55116 KB Output is correct
22 Correct 24 ms 55068 KB Output is correct
23 Correct 23 ms 55096 KB Output is correct
24 Correct 25 ms 55116 KB Output is correct
25 Correct 24 ms 55048 KB Output is correct
26 Correct 23 ms 55060 KB Output is correct
27 Correct 24 ms 55164 KB Output is correct
28 Correct 26 ms 55360 KB Output is correct
29 Correct 26 ms 55312 KB Output is correct
30 Correct 26 ms 55364 KB Output is correct
31 Correct 26 ms 55372 KB Output is correct
32 Correct 27 ms 55304 KB Output is correct
33 Correct 28 ms 55288 KB Output is correct
34 Correct 27 ms 55372 KB Output is correct
35 Correct 301 ms 80472 KB Output is correct
36 Correct 257 ms 80836 KB Output is correct
37 Correct 301 ms 80516 KB Output is correct
38 Correct 297 ms 86480 KB Output is correct
39 Correct 332 ms 81972 KB Output is correct
40 Correct 255 ms 81608 KB Output is correct
41 Correct 594 ms 84020 KB Output is correct
42 Correct 205 ms 70084 KB Output is correct
43 Correct 89 ms 65824 KB Output is correct
44 Correct 399 ms 82040 KB Output is correct
45 Correct 531 ms 82480 KB Output is correct
46 Correct 536 ms 77580 KB Output is correct
47 Correct 531 ms 77564 KB Output is correct
48 Correct 349 ms 83600 KB Output is correct
49 Correct 322 ms 89292 KB Output is correct
50 Correct 377 ms 86660 KB Output is correct
51 Correct 361 ms 86692 KB Output is correct
52 Correct 26 ms 55108 KB Output is correct
53 Correct 556 ms 87296 KB Output is correct
54 Correct 368 ms 85156 KB Output is correct
55 Correct 475 ms 85384 KB Output is correct
56 Correct 513 ms 80756 KB Output is correct
57 Correct 1589 ms 173788 KB Output is correct
58 Correct 1388 ms 202988 KB Output is correct
59 Correct 1803 ms 203184 KB Output is correct
60 Correct 1795 ms 203328 KB Output is correct
61 Correct 3325 ms 191176 KB Output is correct
62 Correct 2090 ms 179272 KB Output is correct
63 Correct 2523 ms 178656 KB Output is correct
64 Correct 3084 ms 180368 KB Output is correct
65 Correct 321 ms 84020 KB Output is correct
66 Correct 290 ms 89772 KB Output is correct
67 Correct 358 ms 87684 KB Output is correct
68 Correct 361 ms 87616 KB Output is correct
69 Correct 547 ms 84136 KB Output is correct
70 Correct 24 ms 55048 KB Output is correct
71 Correct 553 ms 87244 KB Output is correct
72 Correct 366 ms 85108 KB Output is correct
73 Correct 461 ms 85248 KB Output is correct
74 Correct 489 ms 80760 KB Output is correct
75 Correct 1608 ms 196268 KB Output is correct
76 Correct 1385 ms 225548 KB Output is correct
77 Correct 1810 ms 212536 KB Output is correct
78 Correct 1797 ms 212780 KB Output is correct
79 Correct 3349 ms 212660 KB Output is correct
80 Correct 2011 ms 200276 KB Output is correct
81 Correct 2596 ms 198160 KB Output is correct
82 Correct 3045 ms 180392 KB Output is correct
83 Correct 3198 ms 200184 KB Output is correct