Submission #769028

# Submission time Handle Problem Language Result Execution time Memory
769028 2023-06-29T05:19:43 Z nguyentunglam Two Dishes (JOI19_dishes) C++17
74 / 100
3741 ms 167892 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 1e6 + 10;
long long a[N], b[N], s[N], t[N], p[N], q[N];
vector<int> event[N];
int n, m;
long long T[N << 2], lazy[N << 2];
void push(int s, int l, int r) {
    if (lazy[s] == 0) return;
    T[s] += lazy[s];
    if (l != r) {
        lazy[s << 1] += lazy[s];
        lazy[s << 1 | 1] += lazy[s];
    }
    lazy[s] = 0;
}

void up(int s, int l, int r, int from, int to, long long val, bool type) {
    push(s, l, r);
    if (l > to || r < from) return;
    if (from <= l && r <= to) {
        if (type) {
            T[s] = max(T[s], val);
        }
        else {
            lazy[s] += val;
            push(s, l, r);
        }
        return;
    }
    int mid = l + r >> 1;
    up(s << 1, l, mid, from, to, val, type);
    up(s << 1 | 1, mid + 1, r, from, to, val, type);
    T[s] = max(T[s << 1], T[s << 1 | 1]);
}

long long get(int s, int l, int r, int from, int to) {
    push(s, l, r);
    if (l > to || r < from) return -1e18;
    if (from <= l && r <= to) return T[s];
    int mid = l + r >> 1;
    return max(get(s << 1, l, mid, from, to), get(s << 1 | 1, mid + 1, r, from, to));
}


int main() {
    #define task ""
    cin.tie(0) -> sync_with_stdio(0);
    if (fopen ("task.inp", "r")) {
        freopen ("task.inp", "r", stdin);
        freopen ("task.out", "w", stdout);
    }
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> a[i] >> s[i] >> p[i];
        p[i] = p[i];
        a[i] += a[i - 1];
    }
    for(int i = 1; i <= m; i++) {
        cin >> b[i] >> t[i] >> q[i];
        q[i] = q[i];
        b[i] += b[i - 1];
    }
    for(int i = 1; i <= n; i++) {
        int l = 0, r = m, last = -1;
        while (l <= r) {
            int mid = l + r >> 1;
            if (a[i] + b[mid] <= s[i]) {
                last = mid;
                l = mid + 1;
            }
            else r = mid - 1;
        }
        s[i] = last;
    }
    for(int i = 1; i <= m; i++) {
        int l = 0, r = n, last = -1;
        while (l <= r) {
            int mid = l + r >> 1;
            if (b[i] + a[mid] <= t[i]) {
                last = mid;
                l = mid + 1;
            }
            else r = mid - 1;
        }
        t[i] = last;
        if (last >= 0) {
            event[last].push_back(i);
        }
    }
    for(int i = 1; i <= 4 * (m + 1); i++) T[i] = -1e18;
    up(1, 0, m, 0, 0, 0, 1);

    for(int i = 1; i <= n + 1; i++) {
        for(int &j : event[i - 1]) {
            long long f = get(1, 0, m, 0, j - 1);
            up(1, 0, m, j, j, f, 1);
        }
        long long f = get(1, 0, m, 0, s[i]);
        up(1, 0, m, s[i] + 1, s[i] + 1, f, 1);

        up(1, 0, m, 0, s[i], p[i], 0);
        for(int &j : event[i - 1]) {
            up(1, 0, m, j, m, q[j], 0);
        }
    }
    cout << get(1, 0, m, 1, m);
}

Compilation message

dishes.cpp: In function 'void up(int, int, int, int, int, long long int, bool)':
dishes.cpp:35:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |     int mid = l + r >> 1;
      |               ~~^~~
dishes.cpp: In function 'long long int get(int, int, int, int, int)':
dishes.cpp:45:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |     int mid = l + r >> 1;
      |               ~~^~~
dishes.cpp: In function 'int main()':
dishes.cpp:75:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   75 |             int mid = l + r >> 1;
      |                       ~~^~~
dishes.cpp:87:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   87 |             int mid = l + r >> 1;
      |                       ~~^~~
dishes.cpp:54:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:55:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:58:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:59:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 359 ms 60152 KB Output is correct
2 Correct 406 ms 60920 KB Output is correct
3 Correct 246 ms 57848 KB Output is correct
4 Correct 321 ms 59312 KB Output is correct
5 Correct 14 ms 23816 KB Output is correct
6 Correct 341 ms 59360 KB Output is correct
7 Correct 177 ms 46208 KB Output is correct
8 Correct 70 ms 35476 KB Output is correct
9 Correct 246 ms 58824 KB Output is correct
10 Correct 346 ms 57292 KB Output is correct
11 Correct 218 ms 52232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23748 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
3 Correct 13 ms 23876 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 13 ms 23848 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 14 ms 23852 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23756 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 13 ms 23872 KB Output is correct
14 Correct 12 ms 23764 KB Output is correct
15 Correct 12 ms 23856 KB Output is correct
16 Correct 12 ms 23832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23748 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
3 Correct 13 ms 23876 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 13 ms 23848 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 14 ms 23852 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23756 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 13 ms 23872 KB Output is correct
14 Correct 12 ms 23764 KB Output is correct
15 Correct 12 ms 23856 KB Output is correct
16 Correct 12 ms 23832 KB Output is correct
17 Correct 14 ms 24020 KB Output is correct
18 Correct 14 ms 24020 KB Output is correct
19 Correct 15 ms 24020 KB Output is correct
20 Correct 14 ms 24020 KB Output is correct
21 Correct 16 ms 24016 KB Output is correct
22 Correct 15 ms 24020 KB Output is correct
23 Correct 19 ms 24020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23748 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
3 Correct 13 ms 23876 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 13 ms 23848 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 14 ms 23852 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23756 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 13 ms 23872 KB Output is correct
14 Correct 12 ms 23764 KB Output is correct
15 Correct 12 ms 23856 KB Output is correct
16 Correct 12 ms 23832 KB Output is correct
17 Correct 14 ms 24020 KB Output is correct
18 Correct 14 ms 24020 KB Output is correct
19 Correct 15 ms 24020 KB Output is correct
20 Correct 14 ms 24020 KB Output is correct
21 Correct 16 ms 24016 KB Output is correct
22 Correct 15 ms 24020 KB Output is correct
23 Correct 19 ms 24020 KB Output is correct
24 Correct 273 ms 54352 KB Output is correct
25 Correct 247 ms 55040 KB Output is correct
26 Correct 297 ms 55000 KB Output is correct
27 Correct 268 ms 60432 KB Output is correct
28 Correct 305 ms 56136 KB Output is correct
29 Correct 229 ms 55828 KB Output is correct
30 Correct 496 ms 58272 KB Output is correct
31 Correct 175 ms 44964 KB Output is correct
32 Correct 66 ms 33676 KB Output is correct
33 Correct 333 ms 56412 KB Output is correct
34 Correct 415 ms 56376 KB Output is correct
35 Correct 474 ms 51792 KB Output is correct
36 Correct 460 ms 51696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23748 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
3 Correct 13 ms 23876 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 13 ms 23848 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 14 ms 23852 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23756 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 13 ms 23872 KB Output is correct
14 Correct 12 ms 23764 KB Output is correct
15 Correct 12 ms 23856 KB Output is correct
16 Correct 12 ms 23832 KB Output is correct
17 Correct 14 ms 24020 KB Output is correct
18 Correct 14 ms 24020 KB Output is correct
19 Correct 15 ms 24020 KB Output is correct
20 Correct 14 ms 24020 KB Output is correct
21 Correct 16 ms 24016 KB Output is correct
22 Correct 15 ms 24020 KB Output is correct
23 Correct 19 ms 24020 KB Output is correct
24 Correct 273 ms 54352 KB Output is correct
25 Correct 247 ms 55040 KB Output is correct
26 Correct 297 ms 55000 KB Output is correct
27 Correct 268 ms 60432 KB Output is correct
28 Correct 305 ms 56136 KB Output is correct
29 Correct 229 ms 55828 KB Output is correct
30 Correct 496 ms 58272 KB Output is correct
31 Correct 175 ms 44964 KB Output is correct
32 Correct 66 ms 33676 KB Output is correct
33 Correct 333 ms 56412 KB Output is correct
34 Correct 415 ms 56376 KB Output is correct
35 Correct 474 ms 51792 KB Output is correct
36 Correct 460 ms 51696 KB Output is correct
37 Correct 315 ms 57868 KB Output is correct
38 Correct 311 ms 63436 KB Output is correct
39 Correct 383 ms 60812 KB Output is correct
40 Correct 376 ms 60876 KB Output is correct
41 Correct 12 ms 23764 KB Output is correct
42 Correct 519 ms 61288 KB Output is correct
43 Correct 368 ms 59332 KB Output is correct
44 Correct 427 ms 59112 KB Output is correct
45 Correct 506 ms 54780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23748 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
3 Correct 13 ms 23876 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 13 ms 23848 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 14 ms 23852 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23756 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 13 ms 23872 KB Output is correct
14 Correct 12 ms 23764 KB Output is correct
15 Correct 12 ms 23856 KB Output is correct
16 Correct 12 ms 23832 KB Output is correct
17 Correct 14 ms 24020 KB Output is correct
18 Correct 14 ms 24020 KB Output is correct
19 Correct 15 ms 24020 KB Output is correct
20 Correct 14 ms 24020 KB Output is correct
21 Correct 16 ms 24016 KB Output is correct
22 Correct 15 ms 24020 KB Output is correct
23 Correct 19 ms 24020 KB Output is correct
24 Correct 273 ms 54352 KB Output is correct
25 Correct 247 ms 55040 KB Output is correct
26 Correct 297 ms 55000 KB Output is correct
27 Correct 268 ms 60432 KB Output is correct
28 Correct 305 ms 56136 KB Output is correct
29 Correct 229 ms 55828 KB Output is correct
30 Correct 496 ms 58272 KB Output is correct
31 Correct 175 ms 44964 KB Output is correct
32 Correct 66 ms 33676 KB Output is correct
33 Correct 333 ms 56412 KB Output is correct
34 Correct 415 ms 56376 KB Output is correct
35 Correct 474 ms 51792 KB Output is correct
36 Correct 460 ms 51696 KB Output is correct
37 Correct 315 ms 57868 KB Output is correct
38 Correct 311 ms 63436 KB Output is correct
39 Correct 383 ms 60812 KB Output is correct
40 Correct 376 ms 60876 KB Output is correct
41 Correct 12 ms 23764 KB Output is correct
42 Correct 519 ms 61288 KB Output is correct
43 Correct 368 ms 59332 KB Output is correct
44 Correct 427 ms 59112 KB Output is correct
45 Correct 506 ms 54780 KB Output is correct
46 Correct 1849 ms 132168 KB Output is correct
47 Correct 1752 ms 162608 KB Output is correct
48 Correct 2037 ms 158932 KB Output is correct
49 Correct 2083 ms 167892 KB Output is correct
50 Correct 3741 ms 149004 KB Output is correct
51 Correct 2309 ms 138764 KB Output is correct
52 Correct 2708 ms 135532 KB Output is correct
53 Correct 3386 ms 155000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 359 ms 60152 KB Output is correct
2 Correct 406 ms 60920 KB Output is correct
3 Correct 246 ms 57848 KB Output is correct
4 Correct 321 ms 59312 KB Output is correct
5 Correct 14 ms 23816 KB Output is correct
6 Correct 341 ms 59360 KB Output is correct
7 Correct 177 ms 46208 KB Output is correct
8 Correct 70 ms 35476 KB Output is correct
9 Correct 246 ms 58824 KB Output is correct
10 Correct 346 ms 57292 KB Output is correct
11 Correct 218 ms 52232 KB Output is correct
12 Correct 13 ms 23748 KB Output is correct
13 Correct 13 ms 23764 KB Output is correct
14 Correct 13 ms 23876 KB Output is correct
15 Correct 13 ms 23764 KB Output is correct
16 Correct 12 ms 23764 KB Output is correct
17 Correct 13 ms 23848 KB Output is correct
18 Correct 12 ms 23764 KB Output is correct
19 Correct 14 ms 23852 KB Output is correct
20 Correct 12 ms 23764 KB Output is correct
21 Correct 13 ms 23764 KB Output is correct
22 Correct 12 ms 23756 KB Output is correct
23 Correct 12 ms 23764 KB Output is correct
24 Correct 13 ms 23872 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 12 ms 23856 KB Output is correct
27 Correct 12 ms 23832 KB Output is correct
28 Correct 14 ms 24020 KB Output is correct
29 Correct 14 ms 24020 KB Output is correct
30 Correct 15 ms 24020 KB Output is correct
31 Correct 14 ms 24020 KB Output is correct
32 Correct 16 ms 24016 KB Output is correct
33 Correct 15 ms 24020 KB Output is correct
34 Correct 19 ms 24020 KB Output is correct
35 Correct 273 ms 54352 KB Output is correct
36 Correct 247 ms 55040 KB Output is correct
37 Correct 297 ms 55000 KB Output is correct
38 Correct 268 ms 60432 KB Output is correct
39 Correct 305 ms 56136 KB Output is correct
40 Correct 229 ms 55828 KB Output is correct
41 Correct 496 ms 58272 KB Output is correct
42 Correct 175 ms 44964 KB Output is correct
43 Correct 66 ms 33676 KB Output is correct
44 Correct 333 ms 56412 KB Output is correct
45 Correct 415 ms 56376 KB Output is correct
46 Correct 474 ms 51792 KB Output is correct
47 Correct 460 ms 51696 KB Output is correct
48 Correct 315 ms 57868 KB Output is correct
49 Correct 311 ms 63436 KB Output is correct
50 Correct 383 ms 60812 KB Output is correct
51 Correct 376 ms 60876 KB Output is correct
52 Correct 12 ms 23764 KB Output is correct
53 Correct 519 ms 61288 KB Output is correct
54 Correct 368 ms 59332 KB Output is correct
55 Correct 427 ms 59112 KB Output is correct
56 Correct 506 ms 54780 KB Output is correct
57 Incorrect 313 ms 58208 KB Output isn't correct
58 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 359 ms 60152 KB Output is correct
2 Correct 406 ms 60920 KB Output is correct
3 Correct 246 ms 57848 KB Output is correct
4 Correct 321 ms 59312 KB Output is correct
5 Correct 14 ms 23816 KB Output is correct
6 Correct 341 ms 59360 KB Output is correct
7 Correct 177 ms 46208 KB Output is correct
8 Correct 70 ms 35476 KB Output is correct
9 Correct 246 ms 58824 KB Output is correct
10 Correct 346 ms 57292 KB Output is correct
11 Correct 218 ms 52232 KB Output is correct
12 Correct 13 ms 23748 KB Output is correct
13 Correct 13 ms 23764 KB Output is correct
14 Correct 13 ms 23876 KB Output is correct
15 Correct 13 ms 23764 KB Output is correct
16 Correct 12 ms 23764 KB Output is correct
17 Correct 13 ms 23848 KB Output is correct
18 Correct 12 ms 23764 KB Output is correct
19 Correct 14 ms 23852 KB Output is correct
20 Correct 12 ms 23764 KB Output is correct
21 Correct 13 ms 23764 KB Output is correct
22 Correct 12 ms 23756 KB Output is correct
23 Correct 12 ms 23764 KB Output is correct
24 Correct 13 ms 23872 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 12 ms 23856 KB Output is correct
27 Correct 12 ms 23832 KB Output is correct
28 Correct 14 ms 24020 KB Output is correct
29 Correct 14 ms 24020 KB Output is correct
30 Correct 15 ms 24020 KB Output is correct
31 Correct 14 ms 24020 KB Output is correct
32 Correct 16 ms 24016 KB Output is correct
33 Correct 15 ms 24020 KB Output is correct
34 Correct 19 ms 24020 KB Output is correct
35 Correct 273 ms 54352 KB Output is correct
36 Correct 247 ms 55040 KB Output is correct
37 Correct 297 ms 55000 KB Output is correct
38 Correct 268 ms 60432 KB Output is correct
39 Correct 305 ms 56136 KB Output is correct
40 Correct 229 ms 55828 KB Output is correct
41 Correct 496 ms 58272 KB Output is correct
42 Correct 175 ms 44964 KB Output is correct
43 Correct 66 ms 33676 KB Output is correct
44 Correct 333 ms 56412 KB Output is correct
45 Correct 415 ms 56376 KB Output is correct
46 Correct 474 ms 51792 KB Output is correct
47 Correct 460 ms 51696 KB Output is correct
48 Correct 315 ms 57868 KB Output is correct
49 Correct 311 ms 63436 KB Output is correct
50 Correct 383 ms 60812 KB Output is correct
51 Correct 376 ms 60876 KB Output is correct
52 Correct 12 ms 23764 KB Output is correct
53 Correct 519 ms 61288 KB Output is correct
54 Correct 368 ms 59332 KB Output is correct
55 Correct 427 ms 59112 KB Output is correct
56 Correct 506 ms 54780 KB Output is correct
57 Correct 1849 ms 132168 KB Output is correct
58 Correct 1752 ms 162608 KB Output is correct
59 Correct 2037 ms 158932 KB Output is correct
60 Correct 2083 ms 167892 KB Output is correct
61 Correct 3741 ms 149004 KB Output is correct
62 Correct 2309 ms 138764 KB Output is correct
63 Correct 2708 ms 135532 KB Output is correct
64 Correct 3386 ms 155000 KB Output is correct
65 Incorrect 313 ms 58208 KB Output isn't correct
66 Halted 0 ms 0 KB -