답안 #290037

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
290037 2020-09-03T10:09:18 Z dolphingarlic Two Dishes (JOI19_dishes) C++14
100 / 100
6044 ms 198120 KB
#include <bits/stdc++.h> 
typedef long long ll;
using namespace std;

int n, m;
ll a[1000001], b[1000001];
ll s[1000001], t[1000001];
ll p[1000001], q[1000001];
pair<ll, ll> segtree[4000001];
ll lazy[4000001];

void push_lazy(int node, int l, int r) {
    segtree[node].first += lazy[node];
    segtree[node].second += lazy[node];
    if (l != r) {
        lazy[node * 2] += lazy[node];
        lazy[node * 2 + 1] += lazy[node];
    }
    lazy[node] = 0;
}

void range_add(int a, int b, ll val, int node = 1, int l = 0, int r = m) {
    push_lazy(node, l, r);
    if (b < l || a > r) return;
    if (a <= l && b >= r) {
        lazy[node] = val;
        push_lazy(node, l, r);
    } else {
        int mid = (l + r) / 2;
        range_add(a, b, val, node * 2, l, mid);
        range_add(a, b, val, node * 2 + 1, mid + 1, r);
        segtree[node].first = min(segtree[node * 2].first, segtree[node * 2 + 1].first);
        segtree[node].second = max(segtree[node * 2].second, segtree[node * 2 + 1].second);
    }
}

void range_max(int a, int b, ll val, int node = 1, int l = 0, int r = m) {
    push_lazy(node, l, r);
    if (b < l || a > r || segtree[node].first >= val) return;
    if (a <= l && b >= r && segtree[node].first == segtree[node].second) {
        lazy[node] = val - segtree[node].first;
        push_lazy(node, l, r);
    } else {
        int mid = (l + r) / 2;
        range_max(a, b, val, node * 2, l, mid);
        range_max(a, b, val, node * 2 + 1, mid + 1, r);
        segtree[node].first = min(segtree[node * 2].first, segtree[node * 2 + 1].first);
        segtree[node].second = max(segtree[node * 2].second, segtree[node * 2 + 1].second);
    }
}

ll query(int pos, int node = 1, int l = 0, int r = m) {
    push_lazy(node, l, r);
    if (l == r) return segtree[node].first;
    int mid = (l + r) / 2;
    if (mid < pos) return query(pos, node * 2 + 1, mid + 1, r);
    return query(pos, node * 2, l, mid);
}

int main() {
    iostream::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    ll ans = 0;
    vector<tuple<int, int, ll>> events;
    for (int i = 0; i < n; i++) {
        cin >> a[i + 1] >> s[i] >> p[i];
        a[i + 1] += a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i + 1] >> t[i] >> q[i];
        b[i + 1] += b[i];
        int x = upper_bound(a, a + n + 1, t[i] - b[i + 1]) - a;
        if (x) {
            ans += q[i];
            events.push_back({x, -i, -q[i]});
        }
    }
    for (int i = 0; i < n; i++) {
        int y = upper_bound(b, b + m + 1, s[i] - a[i + 1]) - b;
        if (y) events.push_back({i + 1, -y + 1, p[i]});
    }
    sort(events.begin(), events.end());
    for (tuple<int, int, ll> i : events) {
        int x, y, points;
        tie(x, y, points) = i;
        if (x > n) break;
        range_add(0, -y, points);
        range_max(-y, m, query(-y));
    }
    cout << ans + query(m);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 435 ms 40276 KB Output is correct
2 Correct 489 ms 40532 KB Output is correct
3 Correct 229 ms 31464 KB Output is correct
4 Correct 345 ms 34912 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 427 ms 38292 KB Output is correct
7 Correct 98 ms 15072 KB Output is correct
8 Correct 107 ms 16360 KB Output is correct
9 Correct 236 ms 32544 KB Output is correct
10 Correct 450 ms 35932 KB Output is correct
11 Correct 185 ms 25948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 4 ms 768 KB Output is correct
18 Correct 3 ms 768 KB Output is correct
19 Correct 5 ms 768 KB Output is correct
20 Correct 4 ms 768 KB Output is correct
21 Correct 5 ms 800 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 4 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 4 ms 768 KB Output is correct
18 Correct 3 ms 768 KB Output is correct
19 Correct 5 ms 768 KB Output is correct
20 Correct 4 ms 768 KB Output is correct
21 Correct 5 ms 800 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 4 ms 768 KB Output is correct
24 Correct 367 ms 28772 KB Output is correct
25 Correct 362 ms 37476 KB Output is correct
26 Correct 365 ms 37588 KB Output is correct
27 Correct 389 ms 37712 KB Output is correct
28 Correct 395 ms 38484 KB Output is correct
29 Correct 206 ms 29408 KB Output is correct
30 Correct 820 ms 39228 KB Output is correct
31 Correct 160 ms 26080 KB Output is correct
32 Correct 92 ms 14572 KB Output is correct
33 Correct 479 ms 35640 KB Output is correct
34 Correct 670 ms 38740 KB Output is correct
35 Correct 769 ms 32876 KB Output is correct
36 Correct 746 ms 32596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 4 ms 768 KB Output is correct
18 Correct 3 ms 768 KB Output is correct
19 Correct 5 ms 768 KB Output is correct
20 Correct 4 ms 768 KB Output is correct
21 Correct 5 ms 800 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 4 ms 768 KB Output is correct
24 Correct 367 ms 28772 KB Output is correct
25 Correct 362 ms 37476 KB Output is correct
26 Correct 365 ms 37588 KB Output is correct
27 Correct 389 ms 37712 KB Output is correct
28 Correct 395 ms 38484 KB Output is correct
29 Correct 206 ms 29408 KB Output is correct
30 Correct 820 ms 39228 KB Output is correct
31 Correct 160 ms 26080 KB Output is correct
32 Correct 92 ms 14572 KB Output is correct
33 Correct 479 ms 35640 KB Output is correct
34 Correct 670 ms 38740 KB Output is correct
35 Correct 769 ms 32876 KB Output is correct
36 Correct 746 ms 32596 KB Output is correct
37 Correct 398 ms 40752 KB Output is correct
38 Correct 379 ms 40584 KB Output is correct
39 Correct 437 ms 39504 KB Output is correct
40 Correct 595 ms 39640 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 893 ms 42348 KB Output is correct
43 Correct 560 ms 38624 KB Output is correct
44 Correct 697 ms 41684 KB Output is correct
45 Correct 837 ms 35796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 4 ms 768 KB Output is correct
18 Correct 3 ms 768 KB Output is correct
19 Correct 5 ms 768 KB Output is correct
20 Correct 4 ms 768 KB Output is correct
21 Correct 5 ms 800 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 4 ms 768 KB Output is correct
24 Correct 367 ms 28772 KB Output is correct
25 Correct 362 ms 37476 KB Output is correct
26 Correct 365 ms 37588 KB Output is correct
27 Correct 389 ms 37712 KB Output is correct
28 Correct 395 ms 38484 KB Output is correct
29 Correct 206 ms 29408 KB Output is correct
30 Correct 820 ms 39228 KB Output is correct
31 Correct 160 ms 26080 KB Output is correct
32 Correct 92 ms 14572 KB Output is correct
33 Correct 479 ms 35640 KB Output is correct
34 Correct 670 ms 38740 KB Output is correct
35 Correct 769 ms 32876 KB Output is correct
36 Correct 746 ms 32596 KB Output is correct
37 Correct 398 ms 40752 KB Output is correct
38 Correct 379 ms 40584 KB Output is correct
39 Correct 437 ms 39504 KB Output is correct
40 Correct 595 ms 39640 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 893 ms 42348 KB Output is correct
43 Correct 560 ms 38624 KB Output is correct
44 Correct 697 ms 41684 KB Output is correct
45 Correct 837 ms 35796 KB Output is correct
46 Correct 2131 ms 190496 KB Output is correct
47 Correct 2015 ms 190240 KB Output is correct
48 Correct 2323 ms 184672 KB Output is correct
49 Correct 3213 ms 184716 KB Output is correct
50 Correct 5882 ms 197872 KB Output is correct
51 Correct 3297 ms 177608 KB Output is correct
52 Correct 3968 ms 190012 KB Output is correct
53 Correct 5435 ms 166156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 435 ms 40276 KB Output is correct
2 Correct 489 ms 40532 KB Output is correct
3 Correct 229 ms 31464 KB Output is correct
4 Correct 345 ms 34912 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 427 ms 38292 KB Output is correct
7 Correct 98 ms 15072 KB Output is correct
8 Correct 107 ms 16360 KB Output is correct
9 Correct 236 ms 32544 KB Output is correct
10 Correct 450 ms 35932 KB Output is correct
11 Correct 185 ms 25948 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 4 ms 768 KB Output is correct
29 Correct 3 ms 768 KB Output is correct
30 Correct 5 ms 768 KB Output is correct
31 Correct 4 ms 768 KB Output is correct
32 Correct 5 ms 800 KB Output is correct
33 Correct 5 ms 768 KB Output is correct
34 Correct 4 ms 768 KB Output is correct
35 Correct 367 ms 28772 KB Output is correct
36 Correct 362 ms 37476 KB Output is correct
37 Correct 365 ms 37588 KB Output is correct
38 Correct 389 ms 37712 KB Output is correct
39 Correct 395 ms 38484 KB Output is correct
40 Correct 206 ms 29408 KB Output is correct
41 Correct 820 ms 39228 KB Output is correct
42 Correct 160 ms 26080 KB Output is correct
43 Correct 92 ms 14572 KB Output is correct
44 Correct 479 ms 35640 KB Output is correct
45 Correct 670 ms 38740 KB Output is correct
46 Correct 769 ms 32876 KB Output is correct
47 Correct 746 ms 32596 KB Output is correct
48 Correct 398 ms 40752 KB Output is correct
49 Correct 379 ms 40584 KB Output is correct
50 Correct 437 ms 39504 KB Output is correct
51 Correct 595 ms 39640 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 893 ms 42348 KB Output is correct
54 Correct 560 ms 38624 KB Output is correct
55 Correct 697 ms 41684 KB Output is correct
56 Correct 837 ms 35796 KB Output is correct
57 Correct 412 ms 41080 KB Output is correct
58 Correct 423 ms 41124 KB Output is correct
59 Correct 768 ms 40536 KB Output is correct
60 Correct 447 ms 40532 KB Output is correct
61 Correct 663 ms 39380 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 902 ms 42268 KB Output is correct
64 Correct 542 ms 38624 KB Output is correct
65 Correct 748 ms 41812 KB Output is correct
66 Correct 831 ms 35932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 435 ms 40276 KB Output is correct
2 Correct 489 ms 40532 KB Output is correct
3 Correct 229 ms 31464 KB Output is correct
4 Correct 345 ms 34912 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 427 ms 38292 KB Output is correct
7 Correct 98 ms 15072 KB Output is correct
8 Correct 107 ms 16360 KB Output is correct
9 Correct 236 ms 32544 KB Output is correct
10 Correct 450 ms 35932 KB Output is correct
11 Correct 185 ms 25948 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 4 ms 768 KB Output is correct
29 Correct 3 ms 768 KB Output is correct
30 Correct 5 ms 768 KB Output is correct
31 Correct 4 ms 768 KB Output is correct
32 Correct 5 ms 800 KB Output is correct
33 Correct 5 ms 768 KB Output is correct
34 Correct 4 ms 768 KB Output is correct
35 Correct 367 ms 28772 KB Output is correct
36 Correct 362 ms 37476 KB Output is correct
37 Correct 365 ms 37588 KB Output is correct
38 Correct 389 ms 37712 KB Output is correct
39 Correct 395 ms 38484 KB Output is correct
40 Correct 206 ms 29408 KB Output is correct
41 Correct 820 ms 39228 KB Output is correct
42 Correct 160 ms 26080 KB Output is correct
43 Correct 92 ms 14572 KB Output is correct
44 Correct 479 ms 35640 KB Output is correct
45 Correct 670 ms 38740 KB Output is correct
46 Correct 769 ms 32876 KB Output is correct
47 Correct 746 ms 32596 KB Output is correct
48 Correct 398 ms 40752 KB Output is correct
49 Correct 379 ms 40584 KB Output is correct
50 Correct 437 ms 39504 KB Output is correct
51 Correct 595 ms 39640 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 893 ms 42348 KB Output is correct
54 Correct 560 ms 38624 KB Output is correct
55 Correct 697 ms 41684 KB Output is correct
56 Correct 837 ms 35796 KB Output is correct
57 Correct 2131 ms 190496 KB Output is correct
58 Correct 2015 ms 190240 KB Output is correct
59 Correct 2323 ms 184672 KB Output is correct
60 Correct 3213 ms 184716 KB Output is correct
61 Correct 5882 ms 197872 KB Output is correct
62 Correct 3297 ms 177608 KB Output is correct
63 Correct 3968 ms 190012 KB Output is correct
64 Correct 5435 ms 166156 KB Output is correct
65 Correct 412 ms 41080 KB Output is correct
66 Correct 423 ms 41124 KB Output is correct
67 Correct 768 ms 40536 KB Output is correct
68 Correct 447 ms 40532 KB Output is correct
69 Correct 663 ms 39380 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 902 ms 42268 KB Output is correct
72 Correct 542 ms 38624 KB Output is correct
73 Correct 748 ms 41812 KB Output is correct
74 Correct 831 ms 35932 KB Output is correct
75 Correct 2111 ms 191896 KB Output is correct
76 Correct 2269 ms 191900 KB Output is correct
77 Correct 4201 ms 187116 KB Output is correct
78 Correct 2363 ms 187236 KB Output is correct
79 Correct 6044 ms 198120 KB Output is correct
80 Correct 3337 ms 177968 KB Output is correct
81 Correct 4229 ms 189396 KB Output is correct
82 Correct 5599 ms 165648 KB Output is correct
83 Correct 5603 ms 184736 KB Output is correct