Submission #166512

# Submission time Handle Problem Language Result Execution time Memory
166512 2019-12-02T16:13:18 Z Akashi Two Dishes (JOI19_dishes) C++14
100 / 100
6873 ms 278968 KB
#include <bits/stdc++.h>
using namespace std;

const int SZ = 1e6 + 5;
const long long INF = 1e18;

int n, m;
long long Arb[4000015], Lazy_scad[4000015], Lazy_max[4000015];

long long a[SZ], b[SZ], s[SZ], s1[SZ], s2[SZ], t[SZ], q[SZ], p[SZ];

void propag_scad(int nod){
    if(Lazy_scad[nod] != 0){
        Arb[nod * 2] += Lazy_scad[nod];
        Arb[nod * 2 + 1] += Lazy_scad[nod];
        Lazy_scad[nod * 2] += Lazy_scad[nod];
        Lazy_scad[nod * 2 + 1] += Lazy_scad[nod];
        Lazy_max[nod * 2] += Lazy_scad[nod];
        Lazy_max[nod * 2 + 1] += Lazy_scad[nod];
        Lazy_scad[nod] = 0;
    }
}

void propag_max(int nod){
    if(Lazy_max[nod] != -INF){
        if(Arb[nod * 2] < Lazy_max[nod]){
            Arb[nod * 2] = Lazy_max[nod];
//            Lazy_scad[nod * 2] = 0;
        }
        if(Arb[nod * 2 + 1] < Lazy_max[nod]){
            Arb[nod * 2 + 1] = Lazy_max[nod];
//            Lazy_scad[nod * 2 + 1] = 0;
        }
        Lazy_max[nod * 2] = max(Lazy_max[nod * 2], Lazy_max[nod]);
        Lazy_max[nod * 2 + 1] = max(Lazy_max[nod * 2 + 1], Lazy_max[nod]);

        Lazy_max[nod] = -INF;
    }
}

void update_scad(int x, int y, long long v, int st = 0, int dr = m, int nod = 1){
    if(st != dr) propag_scad(nod), propag_max(nod);

    if(x <= st && dr <= y){
        Lazy_scad[nod] += v;
        Arb[nod] += v;
        return ;
    }

    int mij = (st + dr) / 2;
    if(x <= mij) update_scad(x, y, v, st, mij, nod * 2);
    if(mij + 1 <= y) update_scad(x, y, v, mij + 1, dr, nod * 2 + 1);

    Arb[nod] = max(Arb[nod * 2], Arb[nod * 2 + 1]);
}

void update_max(int x, int y, long long v, int st = 0, int dr = m, int nod = 1){
    if(st != dr) propag_scad(nod), propag_max(nod);

    if(x <= st && dr <= y){
        Lazy_max[nod] = max(v, Lazy_max[nod]);
        Arb[nod] = max(v, Arb[nod]);
        return ;
    }

    int mij = (st + dr) / 2;
    if(x <= mij) update_max(x, y, v, st, mij, nod * 2);
    if(mij + 1 <= y) update_max(x, y, v, mij + 1, dr, nod * 2 + 1);

    Arb[nod] = max(Arb[nod * 2], Arb[nod * 2 + 1]);
}

long long query(int x, int y, int st = 0, int dr = m, int nod = 1){
    if(x <= st && dr <= y) return Arb[nod];
    if(st != dr) propag_scad(nod), propag_max(nod);

    int mij = (st + dr) / 2;
    long long a1 = -INF, a2 = -INF;

    if(x <= mij) a1 = query(x, y, st, mij, nod * 2);
    if(mij + 1 <= y) a2 = query(x, y, mij + 1, dr, nod * 2 + 1);

    return max(a1, a2);
}

vector <pair <int, long long> > v[SZ];

void add_point(int x, int y, long long val){
    v[x].push_back({y, val});
}

int main()
{
//    freopen("1.in", "r", stdin);

    scanf("%d%d", &n, &m);

    for(int i = 1; i <= 4000014 ; ++i) Lazy_max[i] = -INF;

    for(int i = 1; i <= n ; ++i){
        scanf("%lld%lld%lld", &a[i], &s[i], &p[i]);
        s1[i] = s1[i - 1] + a[i];
    }

    for(int i = 1; i <= m ; ++i){
        scanf("%lld%lld%lld", &b[i], &t[i], &q[i]);
        s2[i] = s2[i - 1] + b[i];
    }

    long long Sum = 0;
    for(int i = 1; i <= n ; ++i){
        long long v = s[i] - s1[i];
        if(v < 0) continue ;

        int st = 1, dr = m;
        while(st <= dr){
            int mij = (st + dr) / 2;

            if(s2[mij] <= v) st = mij + 1;
            else dr = mij - 1;
        }

        if(dr < m) add_point(i - 1, dr + 1, -p[i]);
        Sum += p[i];
    }

    for(int i = 1; i <= m ; ++i){
        long long v = t[i] - s2[i];
        if(v < 0) continue ;

        int st = 1, dr = n;
        while(st <= dr){
            int mij = (st + dr) / 2;

            if(s1[mij] <= v) st = mij + 1;
            else dr = mij - 1;
        }

        add_point(dr, i, q[i]);
    }

    for(int i = 0; i <= n ; ++i){
        if(i > 0){
            for(auto it : v[i - 1]){
                long long val = query(0, it.first);
                update_max(it.first, m, val);
            }
        }

        for(auto it : v[i]) update_scad(it.first, m, it.second);
    }

    long long val = query(m, m);
    printf("%lld", Sum + val);

    return 0;
}



























Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:96:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
dishes.cpp:101:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld", &a[i], &s[i], &p[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:106:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld", &b[i], &t[i], &q[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 652 ms 85760 KB Output is correct
2 Correct 648 ms 86252 KB Output is correct
3 Correct 358 ms 79680 KB Output is correct
4 Correct 519 ms 79056 KB Output is correct
5 Correct 51 ms 55236 KB Output is correct
6 Correct 591 ms 84652 KB Output is correct
7 Correct 235 ms 77020 KB Output is correct
8 Correct 167 ms 66584 KB Output is correct
9 Correct 369 ms 84188 KB Output is correct
10 Correct 631 ms 90680 KB Output is correct
11 Correct 397 ms 84444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 55260 KB Output is correct
2 Correct 50 ms 55120 KB Output is correct
3 Correct 49 ms 55160 KB Output is correct
4 Correct 50 ms 55212 KB Output is correct
5 Correct 51 ms 55160 KB Output is correct
6 Correct 53 ms 55132 KB Output is correct
7 Correct 50 ms 55160 KB Output is correct
8 Correct 50 ms 55160 KB Output is correct
9 Correct 50 ms 55204 KB Output is correct
10 Correct 51 ms 55128 KB Output is correct
11 Correct 50 ms 55288 KB Output is correct
12 Correct 50 ms 55160 KB Output is correct
13 Correct 52 ms 55164 KB Output is correct
14 Correct 50 ms 55232 KB Output is correct
15 Correct 49 ms 55164 KB Output is correct
16 Correct 52 ms 55160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 55260 KB Output is correct
2 Correct 50 ms 55120 KB Output is correct
3 Correct 49 ms 55160 KB Output is correct
4 Correct 50 ms 55212 KB Output is correct
5 Correct 51 ms 55160 KB Output is correct
6 Correct 53 ms 55132 KB Output is correct
7 Correct 50 ms 55160 KB Output is correct
8 Correct 50 ms 55160 KB Output is correct
9 Correct 50 ms 55204 KB Output is correct
10 Correct 51 ms 55128 KB Output is correct
11 Correct 50 ms 55288 KB Output is correct
12 Correct 50 ms 55160 KB Output is correct
13 Correct 52 ms 55164 KB Output is correct
14 Correct 50 ms 55232 KB Output is correct
15 Correct 49 ms 55164 KB Output is correct
16 Correct 52 ms 55160 KB Output is correct
17 Correct 54 ms 55560 KB Output is correct
18 Correct 74 ms 55540 KB Output is correct
19 Correct 59 ms 55644 KB Output is correct
20 Correct 54 ms 55544 KB Output is correct
21 Correct 54 ms 55608 KB Output is correct
22 Correct 55 ms 55544 KB Output is correct
23 Correct 55 ms 55544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 55260 KB Output is correct
2 Correct 50 ms 55120 KB Output is correct
3 Correct 49 ms 55160 KB Output is correct
4 Correct 50 ms 55212 KB Output is correct
5 Correct 51 ms 55160 KB Output is correct
6 Correct 53 ms 55132 KB Output is correct
7 Correct 50 ms 55160 KB Output is correct
8 Correct 50 ms 55160 KB Output is correct
9 Correct 50 ms 55204 KB Output is correct
10 Correct 51 ms 55128 KB Output is correct
11 Correct 50 ms 55288 KB Output is correct
12 Correct 50 ms 55160 KB Output is correct
13 Correct 52 ms 55164 KB Output is correct
14 Correct 50 ms 55232 KB Output is correct
15 Correct 49 ms 55164 KB Output is correct
16 Correct 52 ms 55160 KB Output is correct
17 Correct 54 ms 55560 KB Output is correct
18 Correct 74 ms 55540 KB Output is correct
19 Correct 59 ms 55644 KB Output is correct
20 Correct 54 ms 55544 KB Output is correct
21 Correct 54 ms 55608 KB Output is correct
22 Correct 55 ms 55544 KB Output is correct
23 Correct 55 ms 55544 KB Output is correct
24 Correct 562 ms 94432 KB Output is correct
25 Correct 446 ms 89764 KB Output is correct
26 Correct 504 ms 94564 KB Output is correct
27 Correct 467 ms 92776 KB Output is correct
28 Correct 517 ms 91612 KB Output is correct
29 Correct 329 ms 90520 KB Output is correct
30 Correct 1057 ms 98172 KB Output is correct
31 Correct 287 ms 78296 KB Output is correct
32 Correct 160 ms 69752 KB Output is correct
33 Correct 655 ms 91824 KB Output is correct
34 Correct 842 ms 95760 KB Output is correct
35 Correct 1002 ms 92000 KB Output is correct
36 Correct 964 ms 91640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 55260 KB Output is correct
2 Correct 50 ms 55120 KB Output is correct
3 Correct 49 ms 55160 KB Output is correct
4 Correct 50 ms 55212 KB Output is correct
5 Correct 51 ms 55160 KB Output is correct
6 Correct 53 ms 55132 KB Output is correct
7 Correct 50 ms 55160 KB Output is correct
8 Correct 50 ms 55160 KB Output is correct
9 Correct 50 ms 55204 KB Output is correct
10 Correct 51 ms 55128 KB Output is correct
11 Correct 50 ms 55288 KB Output is correct
12 Correct 50 ms 55160 KB Output is correct
13 Correct 52 ms 55164 KB Output is correct
14 Correct 50 ms 55232 KB Output is correct
15 Correct 49 ms 55164 KB Output is correct
16 Correct 52 ms 55160 KB Output is correct
17 Correct 54 ms 55560 KB Output is correct
18 Correct 74 ms 55540 KB Output is correct
19 Correct 59 ms 55644 KB Output is correct
20 Correct 54 ms 55544 KB Output is correct
21 Correct 54 ms 55608 KB Output is correct
22 Correct 55 ms 55544 KB Output is correct
23 Correct 55 ms 55544 KB Output is correct
24 Correct 562 ms 94432 KB Output is correct
25 Correct 446 ms 89764 KB Output is correct
26 Correct 504 ms 94564 KB Output is correct
27 Correct 467 ms 92776 KB Output is correct
28 Correct 517 ms 91612 KB Output is correct
29 Correct 329 ms 90520 KB Output is correct
30 Correct 1057 ms 98172 KB Output is correct
31 Correct 287 ms 78296 KB Output is correct
32 Correct 160 ms 69752 KB Output is correct
33 Correct 655 ms 91824 KB Output is correct
34 Correct 842 ms 95760 KB Output is correct
35 Correct 1002 ms 92000 KB Output is correct
36 Correct 964 ms 91640 KB Output is correct
37 Correct 563 ms 97516 KB Output is correct
38 Correct 516 ms 95808 KB Output is correct
39 Correct 662 ms 96376 KB Output is correct
40 Correct 657 ms 96432 KB Output is correct
41 Correct 50 ms 55160 KB Output is correct
42 Correct 1136 ms 101356 KB Output is correct
43 Correct 690 ms 94848 KB Output is correct
44 Correct 895 ms 98492 KB Output is correct
45 Correct 1037 ms 94984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 55260 KB Output is correct
2 Correct 50 ms 55120 KB Output is correct
3 Correct 49 ms 55160 KB Output is correct
4 Correct 50 ms 55212 KB Output is correct
5 Correct 51 ms 55160 KB Output is correct
6 Correct 53 ms 55132 KB Output is correct
7 Correct 50 ms 55160 KB Output is correct
8 Correct 50 ms 55160 KB Output is correct
9 Correct 50 ms 55204 KB Output is correct
10 Correct 51 ms 55128 KB Output is correct
11 Correct 50 ms 55288 KB Output is correct
12 Correct 50 ms 55160 KB Output is correct
13 Correct 52 ms 55164 KB Output is correct
14 Correct 50 ms 55232 KB Output is correct
15 Correct 49 ms 55164 KB Output is correct
16 Correct 52 ms 55160 KB Output is correct
17 Correct 54 ms 55560 KB Output is correct
18 Correct 74 ms 55540 KB Output is correct
19 Correct 59 ms 55644 KB Output is correct
20 Correct 54 ms 55544 KB Output is correct
21 Correct 54 ms 55608 KB Output is correct
22 Correct 55 ms 55544 KB Output is correct
23 Correct 55 ms 55544 KB Output is correct
24 Correct 562 ms 94432 KB Output is correct
25 Correct 446 ms 89764 KB Output is correct
26 Correct 504 ms 94564 KB Output is correct
27 Correct 467 ms 92776 KB Output is correct
28 Correct 517 ms 91612 KB Output is correct
29 Correct 329 ms 90520 KB Output is correct
30 Correct 1057 ms 98172 KB Output is correct
31 Correct 287 ms 78296 KB Output is correct
32 Correct 160 ms 69752 KB Output is correct
33 Correct 655 ms 91824 KB Output is correct
34 Correct 842 ms 95760 KB Output is correct
35 Correct 1002 ms 92000 KB Output is correct
36 Correct 964 ms 91640 KB Output is correct
37 Correct 563 ms 97516 KB Output is correct
38 Correct 516 ms 95808 KB Output is correct
39 Correct 662 ms 96376 KB Output is correct
40 Correct 657 ms 96432 KB Output is correct
41 Correct 50 ms 55160 KB Output is correct
42 Correct 1136 ms 101356 KB Output is correct
43 Correct 690 ms 94848 KB Output is correct
44 Correct 895 ms 98492 KB Output is correct
45 Correct 1037 ms 94984 KB Output is correct
46 Correct 2774 ms 259268 KB Output is correct
47 Correct 2569 ms 251336 KB Output is correct
48 Correct 3455 ms 247516 KB Output is correct
49 Correct 3433 ms 211684 KB Output is correct
50 Correct 6873 ms 243796 KB Output is correct
51 Correct 4065 ms 212888 KB Output is correct
52 Correct 4862 ms 225584 KB Output is correct
53 Correct 6130 ms 226812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 652 ms 85760 KB Output is correct
2 Correct 648 ms 86252 KB Output is correct
3 Correct 358 ms 79680 KB Output is correct
4 Correct 519 ms 79056 KB Output is correct
5 Correct 51 ms 55236 KB Output is correct
6 Correct 591 ms 84652 KB Output is correct
7 Correct 235 ms 77020 KB Output is correct
8 Correct 167 ms 66584 KB Output is correct
9 Correct 369 ms 84188 KB Output is correct
10 Correct 631 ms 90680 KB Output is correct
11 Correct 397 ms 84444 KB Output is correct
12 Correct 50 ms 55260 KB Output is correct
13 Correct 50 ms 55120 KB Output is correct
14 Correct 49 ms 55160 KB Output is correct
15 Correct 50 ms 55212 KB Output is correct
16 Correct 51 ms 55160 KB Output is correct
17 Correct 53 ms 55132 KB Output is correct
18 Correct 50 ms 55160 KB Output is correct
19 Correct 50 ms 55160 KB Output is correct
20 Correct 50 ms 55204 KB Output is correct
21 Correct 51 ms 55128 KB Output is correct
22 Correct 50 ms 55288 KB Output is correct
23 Correct 50 ms 55160 KB Output is correct
24 Correct 52 ms 55164 KB Output is correct
25 Correct 50 ms 55232 KB Output is correct
26 Correct 49 ms 55164 KB Output is correct
27 Correct 52 ms 55160 KB Output is correct
28 Correct 54 ms 55560 KB Output is correct
29 Correct 74 ms 55540 KB Output is correct
30 Correct 59 ms 55644 KB Output is correct
31 Correct 54 ms 55544 KB Output is correct
32 Correct 54 ms 55608 KB Output is correct
33 Correct 55 ms 55544 KB Output is correct
34 Correct 55 ms 55544 KB Output is correct
35 Correct 562 ms 94432 KB Output is correct
36 Correct 446 ms 89764 KB Output is correct
37 Correct 504 ms 94564 KB Output is correct
38 Correct 467 ms 92776 KB Output is correct
39 Correct 517 ms 91612 KB Output is correct
40 Correct 329 ms 90520 KB Output is correct
41 Correct 1057 ms 98172 KB Output is correct
42 Correct 287 ms 78296 KB Output is correct
43 Correct 160 ms 69752 KB Output is correct
44 Correct 655 ms 91824 KB Output is correct
45 Correct 842 ms 95760 KB Output is correct
46 Correct 1002 ms 92000 KB Output is correct
47 Correct 964 ms 91640 KB Output is correct
48 Correct 563 ms 97516 KB Output is correct
49 Correct 516 ms 95808 KB Output is correct
50 Correct 662 ms 96376 KB Output is correct
51 Correct 657 ms 96432 KB Output is correct
52 Correct 50 ms 55160 KB Output is correct
53 Correct 1136 ms 101356 KB Output is correct
54 Correct 690 ms 94848 KB Output is correct
55 Correct 895 ms 98492 KB Output is correct
56 Correct 1037 ms 94984 KB Output is correct
57 Correct 550 ms 98136 KB Output is correct
58 Correct 507 ms 96416 KB Output is correct
59 Correct 664 ms 97464 KB Output is correct
60 Correct 683 ms 97528 KB Output is correct
61 Correct 1004 ms 98440 KB Output is correct
62 Correct 51 ms 55240 KB Output is correct
63 Correct 1097 ms 101368 KB Output is correct
64 Correct 690 ms 94720 KB Output is correct
65 Correct 911 ms 99176 KB Output is correct
66 Correct 1018 ms 94956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 652 ms 85760 KB Output is correct
2 Correct 648 ms 86252 KB Output is correct
3 Correct 358 ms 79680 KB Output is correct
4 Correct 519 ms 79056 KB Output is correct
5 Correct 51 ms 55236 KB Output is correct
6 Correct 591 ms 84652 KB Output is correct
7 Correct 235 ms 77020 KB Output is correct
8 Correct 167 ms 66584 KB Output is correct
9 Correct 369 ms 84188 KB Output is correct
10 Correct 631 ms 90680 KB Output is correct
11 Correct 397 ms 84444 KB Output is correct
12 Correct 50 ms 55260 KB Output is correct
13 Correct 50 ms 55120 KB Output is correct
14 Correct 49 ms 55160 KB Output is correct
15 Correct 50 ms 55212 KB Output is correct
16 Correct 51 ms 55160 KB Output is correct
17 Correct 53 ms 55132 KB Output is correct
18 Correct 50 ms 55160 KB Output is correct
19 Correct 50 ms 55160 KB Output is correct
20 Correct 50 ms 55204 KB Output is correct
21 Correct 51 ms 55128 KB Output is correct
22 Correct 50 ms 55288 KB Output is correct
23 Correct 50 ms 55160 KB Output is correct
24 Correct 52 ms 55164 KB Output is correct
25 Correct 50 ms 55232 KB Output is correct
26 Correct 49 ms 55164 KB Output is correct
27 Correct 52 ms 55160 KB Output is correct
28 Correct 54 ms 55560 KB Output is correct
29 Correct 74 ms 55540 KB Output is correct
30 Correct 59 ms 55644 KB Output is correct
31 Correct 54 ms 55544 KB Output is correct
32 Correct 54 ms 55608 KB Output is correct
33 Correct 55 ms 55544 KB Output is correct
34 Correct 55 ms 55544 KB Output is correct
35 Correct 562 ms 94432 KB Output is correct
36 Correct 446 ms 89764 KB Output is correct
37 Correct 504 ms 94564 KB Output is correct
38 Correct 467 ms 92776 KB Output is correct
39 Correct 517 ms 91612 KB Output is correct
40 Correct 329 ms 90520 KB Output is correct
41 Correct 1057 ms 98172 KB Output is correct
42 Correct 287 ms 78296 KB Output is correct
43 Correct 160 ms 69752 KB Output is correct
44 Correct 655 ms 91824 KB Output is correct
45 Correct 842 ms 95760 KB Output is correct
46 Correct 1002 ms 92000 KB Output is correct
47 Correct 964 ms 91640 KB Output is correct
48 Correct 563 ms 97516 KB Output is correct
49 Correct 516 ms 95808 KB Output is correct
50 Correct 662 ms 96376 KB Output is correct
51 Correct 657 ms 96432 KB Output is correct
52 Correct 50 ms 55160 KB Output is correct
53 Correct 1136 ms 101356 KB Output is correct
54 Correct 690 ms 94848 KB Output is correct
55 Correct 895 ms 98492 KB Output is correct
56 Correct 1037 ms 94984 KB Output is correct
57 Correct 2774 ms 259268 KB Output is correct
58 Correct 2569 ms 251336 KB Output is correct
59 Correct 3455 ms 247516 KB Output is correct
60 Correct 3433 ms 211684 KB Output is correct
61 Correct 6873 ms 243796 KB Output is correct
62 Correct 4065 ms 212888 KB Output is correct
63 Correct 4862 ms 225584 KB Output is correct
64 Correct 6130 ms 226812 KB Output is correct
65 Correct 550 ms 98136 KB Output is correct
66 Correct 507 ms 96416 KB Output is correct
67 Correct 664 ms 97464 KB Output is correct
68 Correct 683 ms 97528 KB Output is correct
69 Correct 1004 ms 98440 KB Output is correct
70 Correct 51 ms 55240 KB Output is correct
71 Correct 1097 ms 101368 KB Output is correct
72 Correct 690 ms 94720 KB Output is correct
73 Correct 911 ms 99176 KB Output is correct
74 Correct 1018 ms 94956 KB Output is correct
75 Correct 2737 ms 258320 KB Output is correct
76 Correct 2515 ms 200536 KB Output is correct
77 Correct 3532 ms 213452 KB Output is correct
78 Correct 3503 ms 233708 KB Output is correct
79 Correct 6867 ms 278968 KB Output is correct
80 Correct 3795 ms 241844 KB Output is correct
81 Correct 5057 ms 255088 KB Output is correct
82 Correct 6852 ms 246348 KB Output is correct
83 Correct 6288 ms 262460 KB Output is correct