답안 #875922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
875922 2023-11-20T18:44:43 Z vjudge1 Two Dishes (JOI19_dishes) C++17
74 / 100
4400 ms 309956 KB
// https://oj.uz/problem/view/JOI19_dishes

#include <bits/stdc++.h>
using namespace std;

const int64_t inf = 1e18;

class segtree_t {
       public:
        segtree_t *left, *right;
        int l, r, m;
        int64_t val, lazy_add, lazy_max;

        segtree_t(int l, int r) : l(l), r(r), m(l + r >> 1), val(0), lazy_add(0), lazy_max(-inf) {
                if (l == r) return;
                left = new segtree_t(l, m);
                right = new segtree_t(m + 1, r);
        }

        void update_add(int s, int t, int64_t x) {
                if (l > t || r < s) return;
                if (s <= l && r <= t) {
                        val += x;
                        lazy_add += x;
                        lazy_max += x;
                        return;
                }
                Down();
                left->update_add(s, t, x);
                right->update_add(s, t, x);
                Up();
        }

        void update_max(int s, int t, int64_t x) {
                if (l > t || r < s) return;
                if (s <= l && r <= t) {
                        val = max(val, x);
                        lazy_max = max(lazy_max, x);
                        return;
                }
                Down();
                left->update_max(s, t, x);
                right->update_max(s, t, x);
                Up();
        }

        int64_t get(int s, int t) {
                if (l > t || r < s) return -inf;
                if (s <= l && r <= t) return val;
                Down();
                return max(left->get(s, t), right->get(s, t));
        }

        void Down() {
                left->lazy_add += lazy_add;
                right->lazy_add += lazy_add;
                left->lazy_max += lazy_add;
                right->lazy_max += lazy_add;
                left->val += lazy_add;
                right->val += lazy_add;
                left->val = max(left->val, lazy_max);
                right->val = max(right->val, lazy_max);
                left->lazy_max = max(left->lazy_max, lazy_max);
                right->lazy_max = max(right->lazy_max, lazy_max);
                lazy_add = 0;
                lazy_max = -inf;
        }

        void Up() {
                val = max(left->val, right->val);
        }
};

int32_t main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);

        int n, m;
        cin >> n >> m;
        vector<int64_t> a(n + 1), s(n), p(n);
        vector<int64_t> b(m + 1), t(m), q(m);
        for (int i = 0; i < n; i++) cin >> a[i + 1] >> s[i] >> p[i];
        for (int i = 0; i < m; i++) cin >> b[i + 1] >> t[i] >> q[i];
        for (int i = 0; i < n; i++) a[i + 1] += a[i];
        for (int i = 0; i < m; i++) b[i + 1] += b[i];
        for (int i = 0; i < n; i++) s[i] -= a[i + 1];
        for (int i = 0; i < m; i++) t[i] -= b[i + 1];
        vector<int> c(n), d(m);
        for (int i = 0; i < n; i++) c[i] = upper_bound(b.begin(), b.end(), s[i]) - b.begin() - 1;
        for (int i = 0; i < m; i++) d[i] = upper_bound(a.begin(), a.end(), t[i]) - a.begin() - 1;

        segtree_t *dp = new segtree_t(0, m);
        vector<vector<pair<int, int>>> upd(n);
        for (int i = 0; i < m; i++) {
                if (d[i] == 0) dp->update_add(i + 1, m, q[i]);
                if (d[i] > 0) upd[d[i] - 1].emplace_back(i + 1, q[i]);
        }
        for (int i = 0; i < n; i++) {
                sort(upd[i].begin(), upd[i].end());
                upd[i].emplace_back(m + 1, -1);
                if (c[i] != -1) dp->update_add(0, c[i], p[i]);
                int64_t sum = 0;
                dp->update_max(c[i] + 1, upd[i][0].first - 1, dp->get(0, c[i]));
                int last = 0;
                for (int j = 0; j + 1 < upd[i].size(); j++) {
                        sum += upd[i][j].second;
                        int64_t x = dp->get(last, upd[i][j].first - 1);
                        dp->update_add(upd[i][j].first, upd[i][j + 1].first - 1, sum);
                        dp->update_max(upd[i][j].first, upd[i][j + 1].first - 1, x + upd[i][j].second);
                        if (c[i] != -1 && upd[i][j].first <= c[i] && c[i] < upd[i][j + 1].first) {
                                int64_t y = dp->get(upd[i][j].first, c[i]);
                                dp->update_max(c[i], upd[i][j + 1].first - 1, y);
                        }
                        last = upd[i][j].first;
                }
        }
        cout << dp->get(m, m);
}

Compilation message

dishes.cpp: In constructor 'segtree_t::segtree_t(int, int)':
dishes.cpp:14:51: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   14 |         segtree_t(int l, int r) : l(l), r(r), m(l + r >> 1), val(0), lazy_add(0), lazy_max(-inf) {
      |                                                 ~~^~~
dishes.cpp: In function 'int32_t main()':
dishes.cpp:105:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |                 for (int j = 0; j + 1 < upd[i].size(); j++) {
      |                                 ~~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 375 ms 48064 KB Output is correct
2 Correct 432 ms 47700 KB Output is correct
3 Correct 254 ms 48876 KB Output is correct
4 Correct 313 ms 46804 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 375 ms 46184 KB Output is correct
7 Correct 173 ms 33164 KB Output is correct
8 Correct 68 ms 16892 KB Output is correct
9 Correct 256 ms 48872 KB Output is correct
10 Correct 406 ms 47224 KB Output is correct
11 Correct 238 ms 48868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 408 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 408 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 4 ms 860 KB Output is correct
20 Correct 3 ms 868 KB Output is correct
21 Correct 4 ms 860 KB Output is correct
22 Correct 4 ms 836 KB Output is correct
23 Correct 4 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 408 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 4 ms 860 KB Output is correct
20 Correct 3 ms 868 KB Output is correct
21 Correct 4 ms 860 KB Output is correct
22 Correct 4 ms 836 KB Output is correct
23 Correct 4 ms 1112 KB Output is correct
24 Correct 276 ms 58620 KB Output is correct
25 Correct 174 ms 57976 KB Output is correct
26 Correct 301 ms 58852 KB Output is correct
27 Correct 320 ms 58112 KB Output is correct
28 Correct 364 ms 59448 KB Output is correct
29 Correct 238 ms 60264 KB Output is correct
30 Correct 646 ms 59032 KB Output is correct
31 Correct 173 ms 37260 KB Output is correct
32 Correct 62 ms 22044 KB Output is correct
33 Correct 370 ms 57684 KB Output is correct
34 Correct 574 ms 58164 KB Output is correct
35 Correct 605 ms 52568 KB Output is correct
36 Correct 601 ms 52564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 408 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 4 ms 860 KB Output is correct
20 Correct 3 ms 868 KB Output is correct
21 Correct 4 ms 860 KB Output is correct
22 Correct 4 ms 836 KB Output is correct
23 Correct 4 ms 1112 KB Output is correct
24 Correct 276 ms 58620 KB Output is correct
25 Correct 174 ms 57976 KB Output is correct
26 Correct 301 ms 58852 KB Output is correct
27 Correct 320 ms 58112 KB Output is correct
28 Correct 364 ms 59448 KB Output is correct
29 Correct 238 ms 60264 KB Output is correct
30 Correct 646 ms 59032 KB Output is correct
31 Correct 173 ms 37260 KB Output is correct
32 Correct 62 ms 22044 KB Output is correct
33 Correct 370 ms 57684 KB Output is correct
34 Correct 574 ms 58164 KB Output is correct
35 Correct 605 ms 52568 KB Output is correct
36 Correct 601 ms 52564 KB Output is correct
37 Correct 316 ms 61968 KB Output is correct
38 Correct 314 ms 61120 KB Output is correct
39 Correct 408 ms 58456 KB Output is correct
40 Correct 409 ms 58476 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 650 ms 61964 KB Output is correct
43 Correct 387 ms 60672 KB Output is correct
44 Correct 537 ms 60680 KB Output is correct
45 Correct 601 ms 55636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 408 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 4 ms 860 KB Output is correct
20 Correct 3 ms 868 KB Output is correct
21 Correct 4 ms 860 KB Output is correct
22 Correct 4 ms 836 KB Output is correct
23 Correct 4 ms 1112 KB Output is correct
24 Correct 276 ms 58620 KB Output is correct
25 Correct 174 ms 57976 KB Output is correct
26 Correct 301 ms 58852 KB Output is correct
27 Correct 320 ms 58112 KB Output is correct
28 Correct 364 ms 59448 KB Output is correct
29 Correct 238 ms 60264 KB Output is correct
30 Correct 646 ms 59032 KB Output is correct
31 Correct 173 ms 37260 KB Output is correct
32 Correct 62 ms 22044 KB Output is correct
33 Correct 370 ms 57684 KB Output is correct
34 Correct 574 ms 58164 KB Output is correct
35 Correct 605 ms 52568 KB Output is correct
36 Correct 601 ms 52564 KB Output is correct
37 Correct 316 ms 61968 KB Output is correct
38 Correct 314 ms 61120 KB Output is correct
39 Correct 408 ms 58456 KB Output is correct
40 Correct 409 ms 58476 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 650 ms 61964 KB Output is correct
43 Correct 387 ms 60672 KB Output is correct
44 Correct 537 ms 60680 KB Output is correct
45 Correct 601 ms 55636 KB Output is correct
46 Correct 1731 ms 309132 KB Output is correct
47 Correct 1678 ms 305476 KB Output is correct
48 Correct 2256 ms 291584 KB Output is correct
49 Correct 2259 ms 291656 KB Output is correct
50 Correct 4400 ms 309956 KB Output is correct
51 Correct 2406 ms 298788 KB Output is correct
52 Correct 3242 ms 289660 KB Output is correct
53 Correct 4136 ms 278660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 375 ms 48064 KB Output is correct
2 Correct 432 ms 47700 KB Output is correct
3 Correct 254 ms 48876 KB Output is correct
4 Correct 313 ms 46804 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 375 ms 46184 KB Output is correct
7 Correct 173 ms 33164 KB Output is correct
8 Correct 68 ms 16892 KB Output is correct
9 Correct 256 ms 48872 KB Output is correct
10 Correct 406 ms 47224 KB Output is correct
11 Correct 238 ms 48868 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 408 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 4 ms 860 KB Output is correct
31 Correct 3 ms 868 KB Output is correct
32 Correct 4 ms 860 KB Output is correct
33 Correct 4 ms 836 KB Output is correct
34 Correct 4 ms 1112 KB Output is correct
35 Correct 276 ms 58620 KB Output is correct
36 Correct 174 ms 57976 KB Output is correct
37 Correct 301 ms 58852 KB Output is correct
38 Correct 320 ms 58112 KB Output is correct
39 Correct 364 ms 59448 KB Output is correct
40 Correct 238 ms 60264 KB Output is correct
41 Correct 646 ms 59032 KB Output is correct
42 Correct 173 ms 37260 KB Output is correct
43 Correct 62 ms 22044 KB Output is correct
44 Correct 370 ms 57684 KB Output is correct
45 Correct 574 ms 58164 KB Output is correct
46 Correct 605 ms 52568 KB Output is correct
47 Correct 601 ms 52564 KB Output is correct
48 Correct 316 ms 61968 KB Output is correct
49 Correct 314 ms 61120 KB Output is correct
50 Correct 408 ms 58456 KB Output is correct
51 Correct 409 ms 58476 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 650 ms 61964 KB Output is correct
54 Correct 387 ms 60672 KB Output is correct
55 Correct 537 ms 60680 KB Output is correct
56 Correct 601 ms 55636 KB Output is correct
57 Correct 312 ms 62268 KB Output is correct
58 Incorrect 316 ms 61588 KB Output isn't correct
59 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 375 ms 48064 KB Output is correct
2 Correct 432 ms 47700 KB Output is correct
3 Correct 254 ms 48876 KB Output is correct
4 Correct 313 ms 46804 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 375 ms 46184 KB Output is correct
7 Correct 173 ms 33164 KB Output is correct
8 Correct 68 ms 16892 KB Output is correct
9 Correct 256 ms 48872 KB Output is correct
10 Correct 406 ms 47224 KB Output is correct
11 Correct 238 ms 48868 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 408 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 4 ms 860 KB Output is correct
31 Correct 3 ms 868 KB Output is correct
32 Correct 4 ms 860 KB Output is correct
33 Correct 4 ms 836 KB Output is correct
34 Correct 4 ms 1112 KB Output is correct
35 Correct 276 ms 58620 KB Output is correct
36 Correct 174 ms 57976 KB Output is correct
37 Correct 301 ms 58852 KB Output is correct
38 Correct 320 ms 58112 KB Output is correct
39 Correct 364 ms 59448 KB Output is correct
40 Correct 238 ms 60264 KB Output is correct
41 Correct 646 ms 59032 KB Output is correct
42 Correct 173 ms 37260 KB Output is correct
43 Correct 62 ms 22044 KB Output is correct
44 Correct 370 ms 57684 KB Output is correct
45 Correct 574 ms 58164 KB Output is correct
46 Correct 605 ms 52568 KB Output is correct
47 Correct 601 ms 52564 KB Output is correct
48 Correct 316 ms 61968 KB Output is correct
49 Correct 314 ms 61120 KB Output is correct
50 Correct 408 ms 58456 KB Output is correct
51 Correct 409 ms 58476 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 650 ms 61964 KB Output is correct
54 Correct 387 ms 60672 KB Output is correct
55 Correct 537 ms 60680 KB Output is correct
56 Correct 601 ms 55636 KB Output is correct
57 Correct 1731 ms 309132 KB Output is correct
58 Correct 1678 ms 305476 KB Output is correct
59 Correct 2256 ms 291584 KB Output is correct
60 Correct 2259 ms 291656 KB Output is correct
61 Correct 4400 ms 309956 KB Output is correct
62 Correct 2406 ms 298788 KB Output is correct
63 Correct 3242 ms 289660 KB Output is correct
64 Correct 4136 ms 278660 KB Output is correct
65 Correct 312 ms 62268 KB Output is correct
66 Incorrect 316 ms 61588 KB Output isn't correct
67 Halted 0 ms 0 KB -