Submission #623016

# Submission time Handle Problem Language Result Execution time Memory
623016 2022-08-05T04:10:09 Z Joshc Two Dishes (JOI19_dishes) C++11
100 / 100
4222 ms 352080 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
const int MAX_N = 2e6+5;
 
struct line {
    ll x, y, val;
};
 
bool comp(line a, line b) {
    if (a.x != b.x) return a.x < b.x;
    if (a.y != b.y) return a.y > b.y;
    return a.val < b.val;
}
 
struct node {
    ll val = 0, add = 0, mx = -1e16;
};
vector<node> seg(4*MAX_N);
 
void push(int v) {
    seg[v<<1].add += seg[v].add;
    seg[v<<1].mx = max(seg[v<<1].mx+seg[v].add, seg[v].mx);
    seg[v<<1].val = max(seg[v<<1].val+seg[v].add, seg[v].mx);
    seg[v<<1|1].add += seg[v].add;
    seg[v<<1|1].mx = max(seg[v<<1|1].mx+seg[v].add, seg[v].mx);
    seg[v<<1|1].val = max(seg[v<<1|1].val+seg[v].add, seg[v].mx);
    seg[v].add = 0;
    seg[v].mx = -1e16;
}
 
void update(int v, int tl, int tr, int l, int r, ll add, ll mx) {
    if (l > r) return;
    if (l == tl && r == tr) {
        seg[v].val = max(seg[v].val+add, mx);
        seg[v].add += add;
        seg[v].mx = max(seg[v].mx+add, mx);
    } else {
        int tm = (tl+tr) >> 1;
        push(v);
        update(v<<1, tl, tm, l, min(r, tm), add, mx);
        update(v<<1|1, tm+1, tr, max(l, tm+1), r, add, mx);
        seg[v].val = max(seg[v<<1].val, seg[v<<1|1].val);
    }
}
 
ll query(int v, int tl, int tr, int l, int r) {
    if (l > r) return -1e16;
    if (l == tl && r == tr) return seg[v].val;
    int tm = (tl+tr) >> 1;
    push(v);
    return max(query(v<<1, tl, tm, l, min(r, tm)), query(v<<1|1, tm+1, tr, max(l, tm+1), r));
}
 
ll a[MAX_N], b[MAX_N], p[MAX_N], q[MAX_N], s[MAX_N], t[MAX_N];
vector<line> ranges; 
 
int main() {
    int n, m;
    ll ans = 0;
    scanf("%d%d", &n, &m);
    for (int i=1; i<=n; i++) {
        scanf("%lld%lld%lld", &a[i], &s[i], &p[i]);
        a[i] += a[i-1];
    }
    for (int i=1; i<=m; i++) {
        scanf("%lld%lld%lld", &b[i], &t[i], &q[i]);
        b[i] += b[i-1];
    }
    for (int i=1; i<=n; i++) {
        if (a[i] > s[i]) continue;
        int low = 0, high = m, mid;
        while (low != high) {
            mid = (low+high+1) >> 1;
            if (a[i]+b[mid] <= s[i]) low = mid;
            else high = mid-1;
        }
        if (low < m) ranges.push_back(line{i, low+1, p[i]});
        else ans += p[i];
    }
    for (int i=1; i<=m; i++) {
        if (b[i] > t[i]) continue;
        int low = 0, high = n, mid;
        while (low != high) {
            mid = (low+high+1) >> 1;
            if (b[i]+a[mid] <= t[i]) low = mid;
            else high = mid-1;
        }
        ans += q[i];
        if (low < n) ranges.push_back(line{low+1, i, -q[i]});
    }
    sort(ranges.begin(), ranges.end(), comp);
    for (auto r : ranges) {
        update(1, 1, 2000001, 1, r.y, r.val, -1e16);
        ll cur = query(1, 1, 2000001, 1, r.y);
        update(1, 1, 2000001, r.y+1, 2000001, 0, cur);
    }
    printf("%lld\n", ans+seg[1].val);
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
dishes.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         scanf("%lld%lld%lld", &a[i], &s[i], &p[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf("%lld%lld%lld", &b[i], &t[i], &q[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 628 ms 223572 KB Output is correct
2 Correct 620 ms 223596 KB Output is correct
3 Correct 230 ms 210964 KB Output is correct
4 Correct 507 ms 217404 KB Output is correct
5 Correct 74 ms 188148 KB Output is correct
6 Correct 582 ms 222952 KB Output is correct
7 Correct 145 ms 199628 KB Output is correct
8 Correct 145 ms 199844 KB Output is correct
9 Correct 242 ms 211876 KB Output is correct
10 Correct 662 ms 217344 KB Output is correct
11 Correct 199 ms 205452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 188164 KB Output is correct
2 Correct 78 ms 188196 KB Output is correct
3 Correct 73 ms 188108 KB Output is correct
4 Correct 74 ms 188108 KB Output is correct
5 Correct 77 ms 188196 KB Output is correct
6 Correct 77 ms 188156 KB Output is correct
7 Correct 74 ms 188212 KB Output is correct
8 Correct 76 ms 188192 KB Output is correct
9 Correct 73 ms 188168 KB Output is correct
10 Correct 74 ms 188276 KB Output is correct
11 Correct 74 ms 188108 KB Output is correct
12 Correct 73 ms 188116 KB Output is correct
13 Correct 75 ms 188192 KB Output is correct
14 Correct 74 ms 188176 KB Output is correct
15 Correct 75 ms 188132 KB Output is correct
16 Correct 76 ms 188204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 188164 KB Output is correct
2 Correct 78 ms 188196 KB Output is correct
3 Correct 73 ms 188108 KB Output is correct
4 Correct 74 ms 188108 KB Output is correct
5 Correct 77 ms 188196 KB Output is correct
6 Correct 77 ms 188156 KB Output is correct
7 Correct 74 ms 188212 KB Output is correct
8 Correct 76 ms 188192 KB Output is correct
9 Correct 73 ms 188168 KB Output is correct
10 Correct 74 ms 188276 KB Output is correct
11 Correct 74 ms 188108 KB Output is correct
12 Correct 73 ms 188116 KB Output is correct
13 Correct 75 ms 188192 KB Output is correct
14 Correct 74 ms 188176 KB Output is correct
15 Correct 75 ms 188132 KB Output is correct
16 Correct 76 ms 188204 KB Output is correct
17 Correct 77 ms 188464 KB Output is correct
18 Correct 79 ms 188464 KB Output is correct
19 Correct 80 ms 188500 KB Output is correct
20 Correct 76 ms 188364 KB Output is correct
21 Correct 81 ms 188600 KB Output is correct
22 Correct 78 ms 188484 KB Output is correct
23 Correct 78 ms 188472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 188164 KB Output is correct
2 Correct 78 ms 188196 KB Output is correct
3 Correct 73 ms 188108 KB Output is correct
4 Correct 74 ms 188108 KB Output is correct
5 Correct 77 ms 188196 KB Output is correct
6 Correct 77 ms 188156 KB Output is correct
7 Correct 74 ms 188212 KB Output is correct
8 Correct 76 ms 188192 KB Output is correct
9 Correct 73 ms 188168 KB Output is correct
10 Correct 74 ms 188276 KB Output is correct
11 Correct 74 ms 188108 KB Output is correct
12 Correct 73 ms 188116 KB Output is correct
13 Correct 75 ms 188192 KB Output is correct
14 Correct 74 ms 188176 KB Output is correct
15 Correct 75 ms 188132 KB Output is correct
16 Correct 76 ms 188204 KB Output is correct
17 Correct 77 ms 188464 KB Output is correct
18 Correct 79 ms 188464 KB Output is correct
19 Correct 80 ms 188500 KB Output is correct
20 Correct 76 ms 188364 KB Output is correct
21 Correct 81 ms 188600 KB Output is correct
22 Correct 78 ms 188484 KB Output is correct
23 Correct 78 ms 188472 KB Output is correct
24 Correct 432 ms 214408 KB Output is correct
25 Correct 432 ms 214408 KB Output is correct
26 Correct 415 ms 214584 KB Output is correct
27 Correct 407 ms 214560 KB Output is correct
28 Correct 391 ms 211560 KB Output is correct
29 Correct 215 ms 208852 KB Output is correct
30 Correct 757 ms 220708 KB Output is correct
31 Correct 275 ms 201276 KB Output is correct
32 Correct 244 ms 201340 KB Output is correct
33 Correct 485 ms 214192 KB Output is correct
34 Correct 607 ms 220432 KB Output is correct
35 Correct 710 ms 214224 KB Output is correct
36 Correct 708 ms 214300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 188164 KB Output is correct
2 Correct 78 ms 188196 KB Output is correct
3 Correct 73 ms 188108 KB Output is correct
4 Correct 74 ms 188108 KB Output is correct
5 Correct 77 ms 188196 KB Output is correct
6 Correct 77 ms 188156 KB Output is correct
7 Correct 74 ms 188212 KB Output is correct
8 Correct 76 ms 188192 KB Output is correct
9 Correct 73 ms 188168 KB Output is correct
10 Correct 74 ms 188276 KB Output is correct
11 Correct 74 ms 188108 KB Output is correct
12 Correct 73 ms 188116 KB Output is correct
13 Correct 75 ms 188192 KB Output is correct
14 Correct 74 ms 188176 KB Output is correct
15 Correct 75 ms 188132 KB Output is correct
16 Correct 76 ms 188204 KB Output is correct
17 Correct 77 ms 188464 KB Output is correct
18 Correct 79 ms 188464 KB Output is correct
19 Correct 80 ms 188500 KB Output is correct
20 Correct 76 ms 188364 KB Output is correct
21 Correct 81 ms 188600 KB Output is correct
22 Correct 78 ms 188484 KB Output is correct
23 Correct 78 ms 188472 KB Output is correct
24 Correct 432 ms 214408 KB Output is correct
25 Correct 432 ms 214408 KB Output is correct
26 Correct 415 ms 214584 KB Output is correct
27 Correct 407 ms 214560 KB Output is correct
28 Correct 391 ms 211560 KB Output is correct
29 Correct 215 ms 208852 KB Output is correct
30 Correct 757 ms 220708 KB Output is correct
31 Correct 275 ms 201276 KB Output is correct
32 Correct 244 ms 201340 KB Output is correct
33 Correct 485 ms 214192 KB Output is correct
34 Correct 607 ms 220432 KB Output is correct
35 Correct 710 ms 214224 KB Output is correct
36 Correct 708 ms 214300 KB Output is correct
37 Correct 447 ms 217464 KB Output is correct
38 Correct 454 ms 217428 KB Output is correct
39 Correct 684 ms 221008 KB Output is correct
40 Correct 691 ms 221068 KB Output is correct
41 Correct 84 ms 188264 KB Output is correct
42 Correct 766 ms 223820 KB Output is correct
43 Correct 488 ms 217020 KB Output is correct
44 Correct 644 ms 223304 KB Output is correct
45 Correct 751 ms 217404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 188164 KB Output is correct
2 Correct 78 ms 188196 KB Output is correct
3 Correct 73 ms 188108 KB Output is correct
4 Correct 74 ms 188108 KB Output is correct
5 Correct 77 ms 188196 KB Output is correct
6 Correct 77 ms 188156 KB Output is correct
7 Correct 74 ms 188212 KB Output is correct
8 Correct 76 ms 188192 KB Output is correct
9 Correct 73 ms 188168 KB Output is correct
10 Correct 74 ms 188276 KB Output is correct
11 Correct 74 ms 188108 KB Output is correct
12 Correct 73 ms 188116 KB Output is correct
13 Correct 75 ms 188192 KB Output is correct
14 Correct 74 ms 188176 KB Output is correct
15 Correct 75 ms 188132 KB Output is correct
16 Correct 76 ms 188204 KB Output is correct
17 Correct 77 ms 188464 KB Output is correct
18 Correct 79 ms 188464 KB Output is correct
19 Correct 80 ms 188500 KB Output is correct
20 Correct 76 ms 188364 KB Output is correct
21 Correct 81 ms 188600 KB Output is correct
22 Correct 78 ms 188484 KB Output is correct
23 Correct 78 ms 188472 KB Output is correct
24 Correct 432 ms 214408 KB Output is correct
25 Correct 432 ms 214408 KB Output is correct
26 Correct 415 ms 214584 KB Output is correct
27 Correct 407 ms 214560 KB Output is correct
28 Correct 391 ms 211560 KB Output is correct
29 Correct 215 ms 208852 KB Output is correct
30 Correct 757 ms 220708 KB Output is correct
31 Correct 275 ms 201276 KB Output is correct
32 Correct 244 ms 201340 KB Output is correct
33 Correct 485 ms 214192 KB Output is correct
34 Correct 607 ms 220432 KB Output is correct
35 Correct 710 ms 214224 KB Output is correct
36 Correct 708 ms 214300 KB Output is correct
37 Correct 447 ms 217464 KB Output is correct
38 Correct 454 ms 217428 KB Output is correct
39 Correct 684 ms 221008 KB Output is correct
40 Correct 691 ms 221068 KB Output is correct
41 Correct 84 ms 188264 KB Output is correct
42 Correct 766 ms 223820 KB Output is correct
43 Correct 488 ms 217020 KB Output is correct
44 Correct 644 ms 223304 KB Output is correct
45 Correct 751 ms 217404 KB Output is correct
46 Correct 1904 ms 306128 KB Output is correct
47 Correct 1853 ms 306084 KB Output is correct
48 Correct 3277 ms 321428 KB Output is correct
49 Correct 3208 ms 321520 KB Output is correct
50 Correct 4222 ms 330936 KB Output is correct
51 Correct 2427 ms 325240 KB Output is correct
52 Correct 3100 ms 347492 KB Output is correct
53 Correct 3814 ms 323188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 628 ms 223572 KB Output is correct
2 Correct 620 ms 223596 KB Output is correct
3 Correct 230 ms 210964 KB Output is correct
4 Correct 507 ms 217404 KB Output is correct
5 Correct 74 ms 188148 KB Output is correct
6 Correct 582 ms 222952 KB Output is correct
7 Correct 145 ms 199628 KB Output is correct
8 Correct 145 ms 199844 KB Output is correct
9 Correct 242 ms 211876 KB Output is correct
10 Correct 662 ms 217344 KB Output is correct
11 Correct 199 ms 205452 KB Output is correct
12 Correct 76 ms 188164 KB Output is correct
13 Correct 78 ms 188196 KB Output is correct
14 Correct 73 ms 188108 KB Output is correct
15 Correct 74 ms 188108 KB Output is correct
16 Correct 77 ms 188196 KB Output is correct
17 Correct 77 ms 188156 KB Output is correct
18 Correct 74 ms 188212 KB Output is correct
19 Correct 76 ms 188192 KB Output is correct
20 Correct 73 ms 188168 KB Output is correct
21 Correct 74 ms 188276 KB Output is correct
22 Correct 74 ms 188108 KB Output is correct
23 Correct 73 ms 188116 KB Output is correct
24 Correct 75 ms 188192 KB Output is correct
25 Correct 74 ms 188176 KB Output is correct
26 Correct 75 ms 188132 KB Output is correct
27 Correct 76 ms 188204 KB Output is correct
28 Correct 77 ms 188464 KB Output is correct
29 Correct 79 ms 188464 KB Output is correct
30 Correct 80 ms 188500 KB Output is correct
31 Correct 76 ms 188364 KB Output is correct
32 Correct 81 ms 188600 KB Output is correct
33 Correct 78 ms 188484 KB Output is correct
34 Correct 78 ms 188472 KB Output is correct
35 Correct 432 ms 214408 KB Output is correct
36 Correct 432 ms 214408 KB Output is correct
37 Correct 415 ms 214584 KB Output is correct
38 Correct 407 ms 214560 KB Output is correct
39 Correct 391 ms 211560 KB Output is correct
40 Correct 215 ms 208852 KB Output is correct
41 Correct 757 ms 220708 KB Output is correct
42 Correct 275 ms 201276 KB Output is correct
43 Correct 244 ms 201340 KB Output is correct
44 Correct 485 ms 214192 KB Output is correct
45 Correct 607 ms 220432 KB Output is correct
46 Correct 710 ms 214224 KB Output is correct
47 Correct 708 ms 214300 KB Output is correct
48 Correct 447 ms 217464 KB Output is correct
49 Correct 454 ms 217428 KB Output is correct
50 Correct 684 ms 221008 KB Output is correct
51 Correct 691 ms 221068 KB Output is correct
52 Correct 84 ms 188264 KB Output is correct
53 Correct 766 ms 223820 KB Output is correct
54 Correct 488 ms 217020 KB Output is correct
55 Correct 644 ms 223304 KB Output is correct
56 Correct 751 ms 217404 KB Output is correct
57 Correct 436 ms 218004 KB Output is correct
58 Correct 460 ms 218148 KB Output is correct
59 Correct 691 ms 222000 KB Output is correct
60 Correct 709 ms 221920 KB Output is correct
61 Correct 756 ms 220664 KB Output is correct
62 Correct 90 ms 188184 KB Output is correct
63 Correct 771 ms 223904 KB Output is correct
64 Correct 504 ms 217028 KB Output is correct
65 Correct 657 ms 223408 KB Output is correct
66 Correct 699 ms 217524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 628 ms 223572 KB Output is correct
2 Correct 620 ms 223596 KB Output is correct
3 Correct 230 ms 210964 KB Output is correct
4 Correct 507 ms 217404 KB Output is correct
5 Correct 74 ms 188148 KB Output is correct
6 Correct 582 ms 222952 KB Output is correct
7 Correct 145 ms 199628 KB Output is correct
8 Correct 145 ms 199844 KB Output is correct
9 Correct 242 ms 211876 KB Output is correct
10 Correct 662 ms 217344 KB Output is correct
11 Correct 199 ms 205452 KB Output is correct
12 Correct 76 ms 188164 KB Output is correct
13 Correct 78 ms 188196 KB Output is correct
14 Correct 73 ms 188108 KB Output is correct
15 Correct 74 ms 188108 KB Output is correct
16 Correct 77 ms 188196 KB Output is correct
17 Correct 77 ms 188156 KB Output is correct
18 Correct 74 ms 188212 KB Output is correct
19 Correct 76 ms 188192 KB Output is correct
20 Correct 73 ms 188168 KB Output is correct
21 Correct 74 ms 188276 KB Output is correct
22 Correct 74 ms 188108 KB Output is correct
23 Correct 73 ms 188116 KB Output is correct
24 Correct 75 ms 188192 KB Output is correct
25 Correct 74 ms 188176 KB Output is correct
26 Correct 75 ms 188132 KB Output is correct
27 Correct 76 ms 188204 KB Output is correct
28 Correct 77 ms 188464 KB Output is correct
29 Correct 79 ms 188464 KB Output is correct
30 Correct 80 ms 188500 KB Output is correct
31 Correct 76 ms 188364 KB Output is correct
32 Correct 81 ms 188600 KB Output is correct
33 Correct 78 ms 188484 KB Output is correct
34 Correct 78 ms 188472 KB Output is correct
35 Correct 432 ms 214408 KB Output is correct
36 Correct 432 ms 214408 KB Output is correct
37 Correct 415 ms 214584 KB Output is correct
38 Correct 407 ms 214560 KB Output is correct
39 Correct 391 ms 211560 KB Output is correct
40 Correct 215 ms 208852 KB Output is correct
41 Correct 757 ms 220708 KB Output is correct
42 Correct 275 ms 201276 KB Output is correct
43 Correct 244 ms 201340 KB Output is correct
44 Correct 485 ms 214192 KB Output is correct
45 Correct 607 ms 220432 KB Output is correct
46 Correct 710 ms 214224 KB Output is correct
47 Correct 708 ms 214300 KB Output is correct
48 Correct 447 ms 217464 KB Output is correct
49 Correct 454 ms 217428 KB Output is correct
50 Correct 684 ms 221008 KB Output is correct
51 Correct 691 ms 221068 KB Output is correct
52 Correct 84 ms 188264 KB Output is correct
53 Correct 766 ms 223820 KB Output is correct
54 Correct 488 ms 217020 KB Output is correct
55 Correct 644 ms 223304 KB Output is correct
56 Correct 751 ms 217404 KB Output is correct
57 Correct 1904 ms 306128 KB Output is correct
58 Correct 1853 ms 306084 KB Output is correct
59 Correct 3277 ms 321428 KB Output is correct
60 Correct 3208 ms 321520 KB Output is correct
61 Correct 4222 ms 330936 KB Output is correct
62 Correct 2427 ms 325240 KB Output is correct
63 Correct 3100 ms 347492 KB Output is correct
64 Correct 3814 ms 323188 KB Output is correct
65 Correct 436 ms 218004 KB Output is correct
66 Correct 460 ms 218148 KB Output is correct
67 Correct 691 ms 222000 KB Output is correct
68 Correct 709 ms 221920 KB Output is correct
69 Correct 756 ms 220664 KB Output is correct
70 Correct 90 ms 188184 KB Output is correct
71 Correct 771 ms 223904 KB Output is correct
72 Correct 504 ms 217028 KB Output is correct
73 Correct 657 ms 223408 KB Output is correct
74 Correct 699 ms 217524 KB Output is correct
75 Correct 1858 ms 331380 KB Output is correct
76 Correct 1857 ms 331408 KB Output is correct
77 Correct 3254 ms 342812 KB Output is correct
78 Correct 3274 ms 341620 KB Output is correct
79 Correct 4078 ms 352080 KB Output is correct
80 Correct 2384 ms 324184 KB Output is correct
81 Correct 3167 ms 345948 KB Output is correct
82 Correct 3864 ms 321920 KB Output is correct
83 Correct 3975 ms 341084 KB Output is correct