답안 #686769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
686769 2023-01-25T23:42:58 Z wenqi Two Dishes (JOI19_dishes) C++17
100 / 100
4539 ms 259900 KB
// trans rights
 
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
constexpr ll L = 1e16 + 69;
 
struct Node
{
    ll mx;
    ll lazy_sum, lazy_mx;
};
 
vector<Node> nodes(5000000);
 
void clean(int i, int l, int r)
{
    auto &node = nodes[i];
    node.mx += node.lazy_sum;
    node.mx = max(node.mx, node.lazy_mx);
    if (l != r)
    {
        int lc = 2 * i;
        int rc = 2 * i + 1;
        nodes[lc].lazy_mx = max(nodes[lc].lazy_mx + node.lazy_sum, node.lazy_mx);
        nodes[rc].lazy_mx = max(nodes[rc].lazy_mx + node.lazy_sum, node.lazy_mx);
        nodes[lc].lazy_sum += node.lazy_sum;
        nodes[rc].lazy_sum += node.lazy_sum;
    }
    node.lazy_mx = -L, node.lazy_sum = 0;
}
 
void upd(int i, int l, int r, int ql, int qr, ll mx, ll sum)
{
    clean(i, l, r);
    auto &node = nodes[i];
    if (qr < l or ql > r)
        return;
    if (ql <= l and qr >= r)
    {
        node.lazy_mx = max(node.lazy_mx, mx);
        node.lazy_mx += sum;
        node.lazy_sum += sum;
        clean(i, l, r);
        return;
    }
    int lc = 2 * i;
    int rc = 2 * i + 1;
    int m = l + (r - l) / 2;
    upd(lc, l, m, ql, qr, mx, sum);
    upd(rc, m + 1, r, ql, qr, mx, sum);
    node.mx = max(nodes[lc].mx, nodes[rc].mx);
}
 
ll query(int i, int l, int r, int ql, int qr)
{
    clean(i, l, r);
    auto &node = nodes[i];
    if (ql <= l and qr >= r)
        return node.mx;
    int lc = 2 * i;
    int rc = 2 * i + 1;
    int m = l + (r - l) / 2;
    if (ql >= m + 1) return query(rc, m + 1, r, ql, qr);
    if (qr <= m) return query(lc, l, m, ql, qr);
    return max(query(lc, l, m, ql, qr), query(rc, m + 1, r, ql, qr));
}
 
int N, M;
ll A[1000069], B[1000069], S[1000069], T[1000069], P[1000069], Q[1000069];
 
vector<tuple<int, int, int>> lines;
 
int main(int argc, const char *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> M;
    for (int i = 1; i <= N; i++)
    {
        int a, p;
        ll s;
        cin >> a >> s >> p;
        A[i] = a + A[i - 1];
        S[i] = s;
        P[i] = p;
    }
    for (int i = 1; i <= M; i++)
    {
        int b, q;
        ll t;
        cin >> b >> t >> q;
        B[i] = b + B[i - 1];
        T[i] = t;
        Q[i] = q;
    }
    ll base = 0;
    for (int i = 1; i <= N; i++)
    {
        int a = 0, b = M + 2;
        while (b - a > 1)
        {
            int m = a + (b - a) / 2;
            if (A[i] + B[m - 1] > S[i])
                b = m;
            else
                a = m;
        }
        if (a == M + 1)
        {
            base += P[i];
            continue;
        }
        if (a)
            lines.push_back({i, -(a - 1), P[i]});
    }
    for (int i = 1; i <= M; i++)
    {
        int a = 0, b = N + 2;
        while (b - a > 1)
        {
            int m = a + (b - a) / 2;
            if (B[i] + A[m - 1] > T[i])
                b = m;
            else
                a = m;
        }
        if (a == N + 1)
        {
            base += Q[i];
            continue;
        }
        if (a)
        {
            lines.push_back({a, -(i - 1), -Q[i]});
            base += Q[i];
        }
    }
    sort(lines.begin(), lines.end());
    int root = 1;
    for (auto [x, ny, a] : lines)
    {
        int y = -ny;
        upd(root, 0, M, 0, y, -L, a);
        upd(root, 0, M, y + 1, M, query(root, 0, M, 0, y), 0);
    }
    cout << nodes[root].mx + base;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 615 ms 147132 KB Output is correct
2 Correct 585 ms 147100 KB Output is correct
3 Correct 223 ms 140508 KB Output is correct
4 Correct 473 ms 144004 KB Output is correct
5 Correct 48 ms 117752 KB Output is correct
6 Correct 514 ms 146448 KB Output is correct
7 Correct 128 ms 129224 KB Output is correct
8 Correct 115 ms 129424 KB Output is correct
9 Correct 213 ms 141464 KB Output is correct
10 Correct 623 ms 140856 KB Output is correct
11 Correct 170 ms 134848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 117732 KB Output is correct
2 Correct 48 ms 117704 KB Output is correct
3 Correct 48 ms 117676 KB Output is correct
4 Correct 47 ms 117736 KB Output is correct
5 Correct 47 ms 117744 KB Output is correct
6 Correct 47 ms 117708 KB Output is correct
7 Correct 47 ms 117724 KB Output is correct
8 Correct 49 ms 117764 KB Output is correct
9 Correct 46 ms 117704 KB Output is correct
10 Correct 46 ms 117664 KB Output is correct
11 Correct 48 ms 117664 KB Output is correct
12 Correct 49 ms 117752 KB Output is correct
13 Correct 48 ms 117728 KB Output is correct
14 Correct 48 ms 117760 KB Output is correct
15 Correct 50 ms 117684 KB Output is correct
16 Correct 46 ms 117704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 117732 KB Output is correct
2 Correct 48 ms 117704 KB Output is correct
3 Correct 48 ms 117676 KB Output is correct
4 Correct 47 ms 117736 KB Output is correct
5 Correct 47 ms 117744 KB Output is correct
6 Correct 47 ms 117708 KB Output is correct
7 Correct 47 ms 117724 KB Output is correct
8 Correct 49 ms 117764 KB Output is correct
9 Correct 46 ms 117704 KB Output is correct
10 Correct 46 ms 117664 KB Output is correct
11 Correct 48 ms 117664 KB Output is correct
12 Correct 49 ms 117752 KB Output is correct
13 Correct 48 ms 117728 KB Output is correct
14 Correct 48 ms 117760 KB Output is correct
15 Correct 50 ms 117684 KB Output is correct
16 Correct 46 ms 117704 KB Output is correct
17 Correct 48 ms 118000 KB Output is correct
18 Correct 50 ms 117976 KB Output is correct
19 Correct 49 ms 117968 KB Output is correct
20 Correct 50 ms 117952 KB Output is correct
21 Correct 52 ms 118016 KB Output is correct
22 Correct 49 ms 117924 KB Output is correct
23 Correct 50 ms 117928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 117732 KB Output is correct
2 Correct 48 ms 117704 KB Output is correct
3 Correct 48 ms 117676 KB Output is correct
4 Correct 47 ms 117736 KB Output is correct
5 Correct 47 ms 117744 KB Output is correct
6 Correct 47 ms 117708 KB Output is correct
7 Correct 47 ms 117724 KB Output is correct
8 Correct 49 ms 117764 KB Output is correct
9 Correct 46 ms 117704 KB Output is correct
10 Correct 46 ms 117664 KB Output is correct
11 Correct 48 ms 117664 KB Output is correct
12 Correct 49 ms 117752 KB Output is correct
13 Correct 48 ms 117728 KB Output is correct
14 Correct 48 ms 117760 KB Output is correct
15 Correct 50 ms 117684 KB Output is correct
16 Correct 46 ms 117704 KB Output is correct
17 Correct 48 ms 118000 KB Output is correct
18 Correct 50 ms 117976 KB Output is correct
19 Correct 49 ms 117968 KB Output is correct
20 Correct 50 ms 117952 KB Output is correct
21 Correct 52 ms 118016 KB Output is correct
22 Correct 49 ms 117924 KB Output is correct
23 Correct 50 ms 117928 KB Output is correct
24 Correct 400 ms 140948 KB Output is correct
25 Correct 392 ms 140968 KB Output is correct
26 Correct 423 ms 141028 KB Output is correct
27 Correct 396 ms 140992 KB Output is correct
28 Correct 374 ms 139784 KB Output is correct
29 Correct 191 ms 138372 KB Output is correct
30 Correct 707 ms 144236 KB Output is correct
31 Correct 207 ms 129292 KB Output is correct
32 Correct 133 ms 129380 KB Output is correct
33 Correct 454 ms 140688 KB Output is correct
34 Correct 625 ms 143896 KB Output is correct
35 Correct 734 ms 137652 KB Output is correct
36 Correct 723 ms 137748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 117732 KB Output is correct
2 Correct 48 ms 117704 KB Output is correct
3 Correct 48 ms 117676 KB Output is correct
4 Correct 47 ms 117736 KB Output is correct
5 Correct 47 ms 117744 KB Output is correct
6 Correct 47 ms 117708 KB Output is correct
7 Correct 47 ms 117724 KB Output is correct
8 Correct 49 ms 117764 KB Output is correct
9 Correct 46 ms 117704 KB Output is correct
10 Correct 46 ms 117664 KB Output is correct
11 Correct 48 ms 117664 KB Output is correct
12 Correct 49 ms 117752 KB Output is correct
13 Correct 48 ms 117728 KB Output is correct
14 Correct 48 ms 117760 KB Output is correct
15 Correct 50 ms 117684 KB Output is correct
16 Correct 46 ms 117704 KB Output is correct
17 Correct 48 ms 118000 KB Output is correct
18 Correct 50 ms 117976 KB Output is correct
19 Correct 49 ms 117968 KB Output is correct
20 Correct 50 ms 117952 KB Output is correct
21 Correct 52 ms 118016 KB Output is correct
22 Correct 49 ms 117924 KB Output is correct
23 Correct 50 ms 117928 KB Output is correct
24 Correct 400 ms 140948 KB Output is correct
25 Correct 392 ms 140968 KB Output is correct
26 Correct 423 ms 141028 KB Output is correct
27 Correct 396 ms 140992 KB Output is correct
28 Correct 374 ms 139784 KB Output is correct
29 Correct 191 ms 138372 KB Output is correct
30 Correct 707 ms 144236 KB Output is correct
31 Correct 207 ms 129292 KB Output is correct
32 Correct 133 ms 129380 KB Output is correct
33 Correct 454 ms 140688 KB Output is correct
34 Correct 625 ms 143896 KB Output is correct
35 Correct 734 ms 137652 KB Output is correct
36 Correct 723 ms 137748 KB Output is correct
37 Correct 408 ms 144036 KB Output is correct
38 Correct 423 ms 144124 KB Output is correct
39 Correct 635 ms 144468 KB Output is correct
40 Correct 668 ms 144520 KB Output is correct
41 Correct 47 ms 117788 KB Output is correct
42 Correct 746 ms 147204 KB Output is correct
43 Correct 474 ms 143616 KB Output is correct
44 Correct 659 ms 146676 KB Output is correct
45 Correct 751 ms 140720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 117732 KB Output is correct
2 Correct 48 ms 117704 KB Output is correct
3 Correct 48 ms 117676 KB Output is correct
4 Correct 47 ms 117736 KB Output is correct
5 Correct 47 ms 117744 KB Output is correct
6 Correct 47 ms 117708 KB Output is correct
7 Correct 47 ms 117724 KB Output is correct
8 Correct 49 ms 117764 KB Output is correct
9 Correct 46 ms 117704 KB Output is correct
10 Correct 46 ms 117664 KB Output is correct
11 Correct 48 ms 117664 KB Output is correct
12 Correct 49 ms 117752 KB Output is correct
13 Correct 48 ms 117728 KB Output is correct
14 Correct 48 ms 117760 KB Output is correct
15 Correct 50 ms 117684 KB Output is correct
16 Correct 46 ms 117704 KB Output is correct
17 Correct 48 ms 118000 KB Output is correct
18 Correct 50 ms 117976 KB Output is correct
19 Correct 49 ms 117968 KB Output is correct
20 Correct 50 ms 117952 KB Output is correct
21 Correct 52 ms 118016 KB Output is correct
22 Correct 49 ms 117924 KB Output is correct
23 Correct 50 ms 117928 KB Output is correct
24 Correct 400 ms 140948 KB Output is correct
25 Correct 392 ms 140968 KB Output is correct
26 Correct 423 ms 141028 KB Output is correct
27 Correct 396 ms 140992 KB Output is correct
28 Correct 374 ms 139784 KB Output is correct
29 Correct 191 ms 138372 KB Output is correct
30 Correct 707 ms 144236 KB Output is correct
31 Correct 207 ms 129292 KB Output is correct
32 Correct 133 ms 129380 KB Output is correct
33 Correct 454 ms 140688 KB Output is correct
34 Correct 625 ms 143896 KB Output is correct
35 Correct 734 ms 137652 KB Output is correct
36 Correct 723 ms 137748 KB Output is correct
37 Correct 408 ms 144036 KB Output is correct
38 Correct 423 ms 144124 KB Output is correct
39 Correct 635 ms 144468 KB Output is correct
40 Correct 668 ms 144520 KB Output is correct
41 Correct 47 ms 117788 KB Output is correct
42 Correct 746 ms 147204 KB Output is correct
43 Correct 474 ms 143616 KB Output is correct
44 Correct 659 ms 146676 KB Output is correct
45 Correct 751 ms 140720 KB Output is correct
46 Correct 2069 ms 247212 KB Output is correct
47 Correct 2138 ms 247116 KB Output is correct
48 Correct 3282 ms 245736 KB Output is correct
49 Correct 3326 ms 245948 KB Output is correct
50 Correct 4539 ms 259408 KB Output is correct
51 Correct 2648 ms 242680 KB Output is correct
52 Correct 3130 ms 252756 KB Output is correct
53 Correct 4083 ms 228224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 615 ms 147132 KB Output is correct
2 Correct 585 ms 147100 KB Output is correct
3 Correct 223 ms 140508 KB Output is correct
4 Correct 473 ms 144004 KB Output is correct
5 Correct 48 ms 117752 KB Output is correct
6 Correct 514 ms 146448 KB Output is correct
7 Correct 128 ms 129224 KB Output is correct
8 Correct 115 ms 129424 KB Output is correct
9 Correct 213 ms 141464 KB Output is correct
10 Correct 623 ms 140856 KB Output is correct
11 Correct 170 ms 134848 KB Output is correct
12 Correct 50 ms 117732 KB Output is correct
13 Correct 48 ms 117704 KB Output is correct
14 Correct 48 ms 117676 KB Output is correct
15 Correct 47 ms 117736 KB Output is correct
16 Correct 47 ms 117744 KB Output is correct
17 Correct 47 ms 117708 KB Output is correct
18 Correct 47 ms 117724 KB Output is correct
19 Correct 49 ms 117764 KB Output is correct
20 Correct 46 ms 117704 KB Output is correct
21 Correct 46 ms 117664 KB Output is correct
22 Correct 48 ms 117664 KB Output is correct
23 Correct 49 ms 117752 KB Output is correct
24 Correct 48 ms 117728 KB Output is correct
25 Correct 48 ms 117760 KB Output is correct
26 Correct 50 ms 117684 KB Output is correct
27 Correct 46 ms 117704 KB Output is correct
28 Correct 48 ms 118000 KB Output is correct
29 Correct 50 ms 117976 KB Output is correct
30 Correct 49 ms 117968 KB Output is correct
31 Correct 50 ms 117952 KB Output is correct
32 Correct 52 ms 118016 KB Output is correct
33 Correct 49 ms 117924 KB Output is correct
34 Correct 50 ms 117928 KB Output is correct
35 Correct 400 ms 140948 KB Output is correct
36 Correct 392 ms 140968 KB Output is correct
37 Correct 423 ms 141028 KB Output is correct
38 Correct 396 ms 140992 KB Output is correct
39 Correct 374 ms 139784 KB Output is correct
40 Correct 191 ms 138372 KB Output is correct
41 Correct 707 ms 144236 KB Output is correct
42 Correct 207 ms 129292 KB Output is correct
43 Correct 133 ms 129380 KB Output is correct
44 Correct 454 ms 140688 KB Output is correct
45 Correct 625 ms 143896 KB Output is correct
46 Correct 734 ms 137652 KB Output is correct
47 Correct 723 ms 137748 KB Output is correct
48 Correct 408 ms 144036 KB Output is correct
49 Correct 423 ms 144124 KB Output is correct
50 Correct 635 ms 144468 KB Output is correct
51 Correct 668 ms 144520 KB Output is correct
52 Correct 47 ms 117788 KB Output is correct
53 Correct 746 ms 147204 KB Output is correct
54 Correct 474 ms 143616 KB Output is correct
55 Correct 659 ms 146676 KB Output is correct
56 Correct 751 ms 140720 KB Output is correct
57 Correct 412 ms 144500 KB Output is correct
58 Correct 409 ms 144552 KB Output is correct
59 Correct 630 ms 145440 KB Output is correct
60 Correct 637 ms 145360 KB Output is correct
61 Correct 724 ms 144188 KB Output is correct
62 Correct 45 ms 117768 KB Output is correct
63 Correct 757 ms 147308 KB Output is correct
64 Correct 469 ms 143568 KB Output is correct
65 Correct 604 ms 146876 KB Output is correct
66 Correct 691 ms 141008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 615 ms 147132 KB Output is correct
2 Correct 585 ms 147100 KB Output is correct
3 Correct 223 ms 140508 KB Output is correct
4 Correct 473 ms 144004 KB Output is correct
5 Correct 48 ms 117752 KB Output is correct
6 Correct 514 ms 146448 KB Output is correct
7 Correct 128 ms 129224 KB Output is correct
8 Correct 115 ms 129424 KB Output is correct
9 Correct 213 ms 141464 KB Output is correct
10 Correct 623 ms 140856 KB Output is correct
11 Correct 170 ms 134848 KB Output is correct
12 Correct 50 ms 117732 KB Output is correct
13 Correct 48 ms 117704 KB Output is correct
14 Correct 48 ms 117676 KB Output is correct
15 Correct 47 ms 117736 KB Output is correct
16 Correct 47 ms 117744 KB Output is correct
17 Correct 47 ms 117708 KB Output is correct
18 Correct 47 ms 117724 KB Output is correct
19 Correct 49 ms 117764 KB Output is correct
20 Correct 46 ms 117704 KB Output is correct
21 Correct 46 ms 117664 KB Output is correct
22 Correct 48 ms 117664 KB Output is correct
23 Correct 49 ms 117752 KB Output is correct
24 Correct 48 ms 117728 KB Output is correct
25 Correct 48 ms 117760 KB Output is correct
26 Correct 50 ms 117684 KB Output is correct
27 Correct 46 ms 117704 KB Output is correct
28 Correct 48 ms 118000 KB Output is correct
29 Correct 50 ms 117976 KB Output is correct
30 Correct 49 ms 117968 KB Output is correct
31 Correct 50 ms 117952 KB Output is correct
32 Correct 52 ms 118016 KB Output is correct
33 Correct 49 ms 117924 KB Output is correct
34 Correct 50 ms 117928 KB Output is correct
35 Correct 400 ms 140948 KB Output is correct
36 Correct 392 ms 140968 KB Output is correct
37 Correct 423 ms 141028 KB Output is correct
38 Correct 396 ms 140992 KB Output is correct
39 Correct 374 ms 139784 KB Output is correct
40 Correct 191 ms 138372 KB Output is correct
41 Correct 707 ms 144236 KB Output is correct
42 Correct 207 ms 129292 KB Output is correct
43 Correct 133 ms 129380 KB Output is correct
44 Correct 454 ms 140688 KB Output is correct
45 Correct 625 ms 143896 KB Output is correct
46 Correct 734 ms 137652 KB Output is correct
47 Correct 723 ms 137748 KB Output is correct
48 Correct 408 ms 144036 KB Output is correct
49 Correct 423 ms 144124 KB Output is correct
50 Correct 635 ms 144468 KB Output is correct
51 Correct 668 ms 144520 KB Output is correct
52 Correct 47 ms 117788 KB Output is correct
53 Correct 746 ms 147204 KB Output is correct
54 Correct 474 ms 143616 KB Output is correct
55 Correct 659 ms 146676 KB Output is correct
56 Correct 751 ms 140720 KB Output is correct
57 Correct 2069 ms 247212 KB Output is correct
58 Correct 2138 ms 247116 KB Output is correct
59 Correct 3282 ms 245736 KB Output is correct
60 Correct 3326 ms 245948 KB Output is correct
61 Correct 4539 ms 259408 KB Output is correct
62 Correct 2648 ms 242680 KB Output is correct
63 Correct 3130 ms 252756 KB Output is correct
64 Correct 4083 ms 228224 KB Output is correct
65 Correct 412 ms 144500 KB Output is correct
66 Correct 409 ms 144552 KB Output is correct
67 Correct 630 ms 145440 KB Output is correct
68 Correct 637 ms 145360 KB Output is correct
69 Correct 724 ms 144188 KB Output is correct
70 Correct 45 ms 117768 KB Output is correct
71 Correct 757 ms 147308 KB Output is correct
72 Correct 469 ms 143568 KB Output is correct
73 Correct 604 ms 146876 KB Output is correct
74 Correct 691 ms 141008 KB Output is correct
75 Correct 2074 ms 248880 KB Output is correct
76 Correct 2024 ms 249100 KB Output is correct
77 Correct 3250 ms 248364 KB Output is correct
78 Correct 3235 ms 248196 KB Output is correct
79 Correct 4429 ms 259900 KB Output is correct
80 Correct 2546 ms 243064 KB Output is correct
81 Correct 3181 ms 253844 KB Output is correct
82 Correct 4181 ms 227704 KB Output is correct
83 Correct 4155 ms 247872 KB Output is correct