Submission #170782

# Submission time Handle Problem Language Result Execution time Memory
170782 2019-12-26T10:49:58 Z gs18103 Two Dishes (JOI19_dishes) C++14
100 / 100
7713 ms 206308 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define em emplace
#define all(v) v.begin(), v.end()
#define my_assert cout << "!" << endl;

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int MAX = 1110101;
const int INF = (1 << 30) - 1;
const ll LINF = 1LL << 60;

int n, m;
ll A[MAX], S[MAX], P[MAX];
ll B[MAX], T[MAX], Q[MAX];
ll sumA[MAX], sumB[MAX], ans;
ll tree[8*MAX], lazy1[8*MAX], lazy2[8*MAX];

void update_lazy(int node, int s, int e) {
    tree[node] = tree[node] * lazy2[node] + lazy1[node];
    if(s != e) {
        if(lazy2[node] == 1) {
            lazy1[node*2] += lazy1[node];
            lazy1[node*2+1] += lazy1[node];
        }
        else {
            lazy1[node*2] = lazy1[node], lazy2[node*2] = 0;
            lazy1[node*2+1] = lazy1[node], lazy2[node*2+1] = 0;
        }
    }
    lazy1[node] = 0;
    lazy2[node] = 1;
}

void update1(int node, int s, int e, int r, ll val) {
    update_lazy(node, s, e);
    if(s > r) return;
    if(e <= r) {
        lazy1[node] += val;
        update_lazy(node, s, e);
        return;
    }
    int mi = (s + e) / 2;
    update1(node*2, s, mi, r, val);
    update1(node*2+1, mi+1, e, r, val);
    tree[node] = max(tree[node*2], tree[node*2+1]);
}

void update2(int node, int s, int e, int l, int r, ll a, ll b) {
    update_lazy(node, s, e);
    if(s > r || e < l) return;
    if(s >= l && e <= r) {
        lazy2[node] = a;
        lazy1[node] = b;
        update_lazy(node, s, e);
        return;
    }
    int mi = (s + e) / 2;
    update2(node*2, s, mi, l, r, a, b);
    update2(node*2+1, mi+1, e, l, r, a, b);
    tree[node] = max(tree[node*2], tree[node*2+1]);
}

ll cal(int node, int s, int e, int l, int r) {
    update_lazy(node, s, e);
    if(s > r || e < l) return -LINF;
    if(s >= l && e <= r) return tree[node];
    int mi = (s + e) / 2;
    return max(cal(node*2, s, mi, l, r), cal(node*2+1, mi+1, e, l, r));
}

int get(int node, int s, int e, ll val) {
    update_lazy(node, s, e);
    if(s == e) return s;
    update_lazy(node*2, s, e);
    if(tree[node*2] > val) return get(node*2, s, (s+e)/2, val);
    else return get(node*2+1, (s+e)/2+1, e, val);
}

struct point {
    int x, y; ll val;
    point(int x, int y, ll val) : x(x), y(y), val(val) {}
};
vector <point> po;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    for(int i = 1; i < 4 * MAX; i++) lazy2[i] = 1;

    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> A[i] >> S[i] >> P[i];
        sumA[i] = sumA[i-1] + A[i];
    }
    for(int i = 1; i <= m; i++) {
        cin >> B[i] >> T[i] >> Q[i];
        sumB[i] = sumB[i-1] + B[i];
        ans += Q[i];
    }
    for(int i = 1; i <= n; i++) {
        int temp = upper_bound(sumB, sumB+m+1, S[i] - sumA[i]) - sumB - 1;
        if(temp >= 0) po.eb(i, temp, P[i]);
    }
    for(int i = 1; i <= m; i++) {
        int temp = upper_bound(sumA, sumA+n+1, T[i] - sumB[i]) - sumA - 1;
        if(temp < 0) ans -= Q[i];
        else if(temp < n) po.eb(temp+1, i-1, -Q[i]);
    }
    sort(all(po), [](point a, point b) {
        if(a.x == b.x) return a.y > b.y;
        return a.x < b.x;
    });

    ll rem = 0;
    for(int i = 0; i < po.size(); i++) {
        if(i+1 < po.size() && po[i].x == po[i+1].x && po[i].y == po[i+1].y) {
            rem += po[i].val;
            continue;
        }
        update1(1, 0, m, po[i].y, po[i].val + rem);
        ll temp = cal(1, 0, m, 0, po[i].y);
        int idx = m + 1;
        if(cal(1, 0, m, 0, m) > temp) idx = get(1, 0, m, temp);
        update2(1, 0, m, po[i].y+1, idx - 1, 0, temp);
        rem = 0;
    }
    cout << cal(1, 0, m, m, m) + ans;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:120:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < po.size(); i++) {
                    ~~^~~~~~~~~~~
dishes.cpp:121:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(i+1 < po.size() && po[i].x == po[i+1].x && po[i].y == po[i+1].y) {
            ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 656 ms 73892 KB Output is correct
2 Correct 629 ms 73320 KB Output is correct
3 Correct 275 ms 59212 KB Output is correct
4 Correct 481 ms 68248 KB Output is correct
5 Correct 35 ms 35192 KB Output is correct
6 Correct 584 ms 70780 KB Output is correct
7 Correct 136 ms 47144 KB Output is correct
8 Correct 158 ms 52648 KB Output is correct
9 Correct 279 ms 61132 KB Output is correct
10 Correct 564 ms 72560 KB Output is correct
11 Correct 204 ms 59124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 35136 KB Output is correct
2 Correct 30 ms 35112 KB Output is correct
3 Correct 30 ms 35192 KB Output is correct
4 Correct 29 ms 35164 KB Output is correct
5 Correct 29 ms 35212 KB Output is correct
6 Correct 30 ms 35192 KB Output is correct
7 Correct 30 ms 35308 KB Output is correct
8 Correct 30 ms 35192 KB Output is correct
9 Correct 30 ms 35192 KB Output is correct
10 Correct 30 ms 35164 KB Output is correct
11 Correct 30 ms 35192 KB Output is correct
12 Correct 30 ms 35192 KB Output is correct
13 Correct 37 ms 35164 KB Output is correct
14 Correct 30 ms 35192 KB Output is correct
15 Correct 29 ms 35160 KB Output is correct
16 Correct 29 ms 35208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 35136 KB Output is correct
2 Correct 30 ms 35112 KB Output is correct
3 Correct 30 ms 35192 KB Output is correct
4 Correct 29 ms 35164 KB Output is correct
5 Correct 29 ms 35212 KB Output is correct
6 Correct 30 ms 35192 KB Output is correct
7 Correct 30 ms 35308 KB Output is correct
8 Correct 30 ms 35192 KB Output is correct
9 Correct 30 ms 35192 KB Output is correct
10 Correct 30 ms 35164 KB Output is correct
11 Correct 30 ms 35192 KB Output is correct
12 Correct 30 ms 35192 KB Output is correct
13 Correct 37 ms 35164 KB Output is correct
14 Correct 30 ms 35192 KB Output is correct
15 Correct 29 ms 35160 KB Output is correct
16 Correct 29 ms 35208 KB Output is correct
17 Correct 32 ms 35448 KB Output is correct
18 Correct 33 ms 35612 KB Output is correct
19 Correct 35 ms 35676 KB Output is correct
20 Correct 33 ms 35564 KB Output is correct
21 Correct 36 ms 35580 KB Output is correct
22 Correct 36 ms 35536 KB Output is correct
23 Correct 36 ms 35576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 35136 KB Output is correct
2 Correct 30 ms 35112 KB Output is correct
3 Correct 30 ms 35192 KB Output is correct
4 Correct 29 ms 35164 KB Output is correct
5 Correct 29 ms 35212 KB Output is correct
6 Correct 30 ms 35192 KB Output is correct
7 Correct 30 ms 35308 KB Output is correct
8 Correct 30 ms 35192 KB Output is correct
9 Correct 30 ms 35192 KB Output is correct
10 Correct 30 ms 35164 KB Output is correct
11 Correct 30 ms 35192 KB Output is correct
12 Correct 30 ms 35192 KB Output is correct
13 Correct 37 ms 35164 KB Output is correct
14 Correct 30 ms 35192 KB Output is correct
15 Correct 29 ms 35160 KB Output is correct
16 Correct 29 ms 35208 KB Output is correct
17 Correct 32 ms 35448 KB Output is correct
18 Correct 33 ms 35612 KB Output is correct
19 Correct 35 ms 35676 KB Output is correct
20 Correct 33 ms 35564 KB Output is correct
21 Correct 36 ms 35580 KB Output is correct
22 Correct 36 ms 35536 KB Output is correct
23 Correct 36 ms 35576 KB Output is correct
24 Correct 499 ms 60380 KB Output is correct
25 Correct 545 ms 73216 KB Output is correct
26 Correct 494 ms 67744 KB Output is correct
27 Correct 560 ms 73380 KB Output is correct
28 Correct 515 ms 72664 KB Output is correct
29 Correct 260 ms 59552 KB Output is correct
30 Correct 1222 ms 75156 KB Output is correct
31 Correct 283 ms 60788 KB Output is correct
32 Correct 162 ms 49176 KB Output is correct
33 Correct 725 ms 70324 KB Output is correct
34 Correct 937 ms 73648 KB Output is correct
35 Correct 1166 ms 70572 KB Output is correct
36 Correct 1119 ms 70516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 35136 KB Output is correct
2 Correct 30 ms 35112 KB Output is correct
3 Correct 30 ms 35192 KB Output is correct
4 Correct 29 ms 35164 KB Output is correct
5 Correct 29 ms 35212 KB Output is correct
6 Correct 30 ms 35192 KB Output is correct
7 Correct 30 ms 35308 KB Output is correct
8 Correct 30 ms 35192 KB Output is correct
9 Correct 30 ms 35192 KB Output is correct
10 Correct 30 ms 35164 KB Output is correct
11 Correct 30 ms 35192 KB Output is correct
12 Correct 30 ms 35192 KB Output is correct
13 Correct 37 ms 35164 KB Output is correct
14 Correct 30 ms 35192 KB Output is correct
15 Correct 29 ms 35160 KB Output is correct
16 Correct 29 ms 35208 KB Output is correct
17 Correct 32 ms 35448 KB Output is correct
18 Correct 33 ms 35612 KB Output is correct
19 Correct 35 ms 35676 KB Output is correct
20 Correct 33 ms 35564 KB Output is correct
21 Correct 36 ms 35580 KB Output is correct
22 Correct 36 ms 35536 KB Output is correct
23 Correct 36 ms 35576 KB Output is correct
24 Correct 499 ms 60380 KB Output is correct
25 Correct 545 ms 73216 KB Output is correct
26 Correct 494 ms 67744 KB Output is correct
27 Correct 560 ms 73380 KB Output is correct
28 Correct 515 ms 72664 KB Output is correct
29 Correct 260 ms 59552 KB Output is correct
30 Correct 1222 ms 75156 KB Output is correct
31 Correct 283 ms 60788 KB Output is correct
32 Correct 162 ms 49176 KB Output is correct
33 Correct 725 ms 70324 KB Output is correct
34 Correct 937 ms 73648 KB Output is correct
35 Correct 1166 ms 70572 KB Output is correct
36 Correct 1119 ms 70516 KB Output is correct
37 Correct 516 ms 69708 KB Output is correct
38 Correct 589 ms 73984 KB Output is correct
39 Correct 604 ms 76740 KB Output is correct
40 Correct 690 ms 72516 KB Output is correct
41 Correct 30 ms 35108 KB Output is correct
42 Correct 1247 ms 77208 KB Output is correct
43 Correct 753 ms 74108 KB Output is correct
44 Correct 952 ms 76496 KB Output is correct
45 Correct 1184 ms 73092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 35136 KB Output is correct
2 Correct 30 ms 35112 KB Output is correct
3 Correct 30 ms 35192 KB Output is correct
4 Correct 29 ms 35164 KB Output is correct
5 Correct 29 ms 35212 KB Output is correct
6 Correct 30 ms 35192 KB Output is correct
7 Correct 30 ms 35308 KB Output is correct
8 Correct 30 ms 35192 KB Output is correct
9 Correct 30 ms 35192 KB Output is correct
10 Correct 30 ms 35164 KB Output is correct
11 Correct 30 ms 35192 KB Output is correct
12 Correct 30 ms 35192 KB Output is correct
13 Correct 37 ms 35164 KB Output is correct
14 Correct 30 ms 35192 KB Output is correct
15 Correct 29 ms 35160 KB Output is correct
16 Correct 29 ms 35208 KB Output is correct
17 Correct 32 ms 35448 KB Output is correct
18 Correct 33 ms 35612 KB Output is correct
19 Correct 35 ms 35676 KB Output is correct
20 Correct 33 ms 35564 KB Output is correct
21 Correct 36 ms 35580 KB Output is correct
22 Correct 36 ms 35536 KB Output is correct
23 Correct 36 ms 35576 KB Output is correct
24 Correct 499 ms 60380 KB Output is correct
25 Correct 545 ms 73216 KB Output is correct
26 Correct 494 ms 67744 KB Output is correct
27 Correct 560 ms 73380 KB Output is correct
28 Correct 515 ms 72664 KB Output is correct
29 Correct 260 ms 59552 KB Output is correct
30 Correct 1222 ms 75156 KB Output is correct
31 Correct 283 ms 60788 KB Output is correct
32 Correct 162 ms 49176 KB Output is correct
33 Correct 725 ms 70324 KB Output is correct
34 Correct 937 ms 73648 KB Output is correct
35 Correct 1166 ms 70572 KB Output is correct
36 Correct 1119 ms 70516 KB Output is correct
37 Correct 516 ms 69708 KB Output is correct
38 Correct 589 ms 73984 KB Output is correct
39 Correct 604 ms 76740 KB Output is correct
40 Correct 690 ms 72516 KB Output is correct
41 Correct 30 ms 35108 KB Output is correct
42 Correct 1247 ms 77208 KB Output is correct
43 Correct 753 ms 74108 KB Output is correct
44 Correct 952 ms 76496 KB Output is correct
45 Correct 1184 ms 73092 KB Output is correct
46 Correct 2658 ms 151840 KB Output is correct
47 Correct 3093 ms 171724 KB Output is correct
48 Correct 3185 ms 182972 KB Output is correct
49 Correct 3683 ms 162808 KB Output is correct
50 Correct 7681 ms 182520 KB Output is correct
51 Correct 4188 ms 187880 KB Output is correct
52 Correct 5086 ms 193456 KB Output is correct
53 Correct 7075 ms 197884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 656 ms 73892 KB Output is correct
2 Correct 629 ms 73320 KB Output is correct
3 Correct 275 ms 59212 KB Output is correct
4 Correct 481 ms 68248 KB Output is correct
5 Correct 35 ms 35192 KB Output is correct
6 Correct 584 ms 70780 KB Output is correct
7 Correct 136 ms 47144 KB Output is correct
8 Correct 158 ms 52648 KB Output is correct
9 Correct 279 ms 61132 KB Output is correct
10 Correct 564 ms 72560 KB Output is correct
11 Correct 204 ms 59124 KB Output is correct
12 Correct 28 ms 35136 KB Output is correct
13 Correct 30 ms 35112 KB Output is correct
14 Correct 30 ms 35192 KB Output is correct
15 Correct 29 ms 35164 KB Output is correct
16 Correct 29 ms 35212 KB Output is correct
17 Correct 30 ms 35192 KB Output is correct
18 Correct 30 ms 35308 KB Output is correct
19 Correct 30 ms 35192 KB Output is correct
20 Correct 30 ms 35192 KB Output is correct
21 Correct 30 ms 35164 KB Output is correct
22 Correct 30 ms 35192 KB Output is correct
23 Correct 30 ms 35192 KB Output is correct
24 Correct 37 ms 35164 KB Output is correct
25 Correct 30 ms 35192 KB Output is correct
26 Correct 29 ms 35160 KB Output is correct
27 Correct 29 ms 35208 KB Output is correct
28 Correct 32 ms 35448 KB Output is correct
29 Correct 33 ms 35612 KB Output is correct
30 Correct 35 ms 35676 KB Output is correct
31 Correct 33 ms 35564 KB Output is correct
32 Correct 36 ms 35580 KB Output is correct
33 Correct 36 ms 35536 KB Output is correct
34 Correct 36 ms 35576 KB Output is correct
35 Correct 499 ms 60380 KB Output is correct
36 Correct 545 ms 73216 KB Output is correct
37 Correct 494 ms 67744 KB Output is correct
38 Correct 560 ms 73380 KB Output is correct
39 Correct 515 ms 72664 KB Output is correct
40 Correct 260 ms 59552 KB Output is correct
41 Correct 1222 ms 75156 KB Output is correct
42 Correct 283 ms 60788 KB Output is correct
43 Correct 162 ms 49176 KB Output is correct
44 Correct 725 ms 70324 KB Output is correct
45 Correct 937 ms 73648 KB Output is correct
46 Correct 1166 ms 70572 KB Output is correct
47 Correct 1119 ms 70516 KB Output is correct
48 Correct 516 ms 69708 KB Output is correct
49 Correct 589 ms 73984 KB Output is correct
50 Correct 604 ms 76740 KB Output is correct
51 Correct 690 ms 72516 KB Output is correct
52 Correct 30 ms 35108 KB Output is correct
53 Correct 1247 ms 77208 KB Output is correct
54 Correct 753 ms 74108 KB Output is correct
55 Correct 952 ms 76496 KB Output is correct
56 Correct 1184 ms 73092 KB Output is correct
57 Correct 559 ms 72144 KB Output is correct
58 Correct 548 ms 71252 KB Output is correct
59 Correct 699 ms 74444 KB Output is correct
60 Correct 616 ms 77076 KB Output is correct
61 Correct 1038 ms 73056 KB Output is correct
62 Correct 30 ms 35112 KB Output is correct
63 Correct 1231 ms 76632 KB Output is correct
64 Correct 745 ms 75212 KB Output is correct
65 Correct 1004 ms 77060 KB Output is correct
66 Correct 1145 ms 73748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 656 ms 73892 KB Output is correct
2 Correct 629 ms 73320 KB Output is correct
3 Correct 275 ms 59212 KB Output is correct
4 Correct 481 ms 68248 KB Output is correct
5 Correct 35 ms 35192 KB Output is correct
6 Correct 584 ms 70780 KB Output is correct
7 Correct 136 ms 47144 KB Output is correct
8 Correct 158 ms 52648 KB Output is correct
9 Correct 279 ms 61132 KB Output is correct
10 Correct 564 ms 72560 KB Output is correct
11 Correct 204 ms 59124 KB Output is correct
12 Correct 28 ms 35136 KB Output is correct
13 Correct 30 ms 35112 KB Output is correct
14 Correct 30 ms 35192 KB Output is correct
15 Correct 29 ms 35164 KB Output is correct
16 Correct 29 ms 35212 KB Output is correct
17 Correct 30 ms 35192 KB Output is correct
18 Correct 30 ms 35308 KB Output is correct
19 Correct 30 ms 35192 KB Output is correct
20 Correct 30 ms 35192 KB Output is correct
21 Correct 30 ms 35164 KB Output is correct
22 Correct 30 ms 35192 KB Output is correct
23 Correct 30 ms 35192 KB Output is correct
24 Correct 37 ms 35164 KB Output is correct
25 Correct 30 ms 35192 KB Output is correct
26 Correct 29 ms 35160 KB Output is correct
27 Correct 29 ms 35208 KB Output is correct
28 Correct 32 ms 35448 KB Output is correct
29 Correct 33 ms 35612 KB Output is correct
30 Correct 35 ms 35676 KB Output is correct
31 Correct 33 ms 35564 KB Output is correct
32 Correct 36 ms 35580 KB Output is correct
33 Correct 36 ms 35536 KB Output is correct
34 Correct 36 ms 35576 KB Output is correct
35 Correct 499 ms 60380 KB Output is correct
36 Correct 545 ms 73216 KB Output is correct
37 Correct 494 ms 67744 KB Output is correct
38 Correct 560 ms 73380 KB Output is correct
39 Correct 515 ms 72664 KB Output is correct
40 Correct 260 ms 59552 KB Output is correct
41 Correct 1222 ms 75156 KB Output is correct
42 Correct 283 ms 60788 KB Output is correct
43 Correct 162 ms 49176 KB Output is correct
44 Correct 725 ms 70324 KB Output is correct
45 Correct 937 ms 73648 KB Output is correct
46 Correct 1166 ms 70572 KB Output is correct
47 Correct 1119 ms 70516 KB Output is correct
48 Correct 516 ms 69708 KB Output is correct
49 Correct 589 ms 73984 KB Output is correct
50 Correct 604 ms 76740 KB Output is correct
51 Correct 690 ms 72516 KB Output is correct
52 Correct 30 ms 35108 KB Output is correct
53 Correct 1247 ms 77208 KB Output is correct
54 Correct 753 ms 74108 KB Output is correct
55 Correct 952 ms 76496 KB Output is correct
56 Correct 1184 ms 73092 KB Output is correct
57 Correct 2658 ms 151840 KB Output is correct
58 Correct 3093 ms 171724 KB Output is correct
59 Correct 3185 ms 182972 KB Output is correct
60 Correct 3683 ms 162808 KB Output is correct
61 Correct 7681 ms 182520 KB Output is correct
62 Correct 4188 ms 187880 KB Output is correct
63 Correct 5086 ms 193456 KB Output is correct
64 Correct 7075 ms 197884 KB Output is correct
65 Correct 559 ms 72144 KB Output is correct
66 Correct 548 ms 71252 KB Output is correct
67 Correct 699 ms 74444 KB Output is correct
68 Correct 616 ms 77076 KB Output is correct
69 Correct 1038 ms 73056 KB Output is correct
70 Correct 30 ms 35112 KB Output is correct
71 Correct 1231 ms 76632 KB Output is correct
72 Correct 745 ms 75212 KB Output is correct
73 Correct 1004 ms 77060 KB Output is correct
74 Correct 1145 ms 73748 KB Output is correct
75 Correct 2903 ms 187336 KB Output is correct
76 Correct 2829 ms 176816 KB Output is correct
77 Correct 3732 ms 179480 KB Output is correct
78 Correct 3218 ms 206308 KB Output is correct
79 Correct 7713 ms 199996 KB Output is correct
80 Correct 4167 ms 179388 KB Output is correct
81 Correct 5429 ms 186944 KB Output is correct
82 Correct 7176 ms 188260 KB Output is correct
83 Correct 7030 ms 193704 KB Output is correct