답안 #944900

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944900 2024-03-13T07:42:08 Z LOLOLO Two Dishes (JOI19_dishes) C++17
100 / 100
3348 ms 279116 KB
#include <bits/stdc++.h>
typedef long long ll;

#define           f    first
#define           s    second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)

using namespace std;
const int N = 1e6 + 10;
ll A[N], B[N], SA[N], SB[N], S[N], T[N], Q[N], P[N];
vector <pair <ll, ll>> pos[N];

struct ST{
    vector <ll> seg, laz;
    ST(int n) {
        for (int i = 0; i <= n * 4 + 100; i++) {
            seg.pb(0);
            laz.pb(0);
        }
    }

    void push(int id) {
        ll &t = laz[id];
        laz[id * 2] += t;
        laz[id * 2 + 1] += t;
        seg[id * 2] += t;
        seg[id * 2 + 1] += t;
        t = 0;
    }

    void upd(int id, int l, int r, int u, int v, ll t) {
        if (l > v || r < u)
            return;

        if (l >= u && r <= v) {
            laz[id] += t;
            seg[id] += t;
            return;
        }

        push(id);
        int m = (l + r) / 2;
        upd(id * 2, l, m, u, v, t);
        upd(id * 2 + 1, m + 1, r, u, v, t);
        seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
    }

    void point(int id, int l, int r, int p, ll v) {
        if (l > p || r < p)
            return;

        if (l == r) {
            seg[id] = max(seg[id], v);
            return;
        }

        push(id);
        int m = (l + r) / 2;
        point(id * 2, l, m, p, v);
        point(id * 2 + 1, m + 1, r, p, v);
        seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
    }

    ll get(int id, int l, int r, int u, int v) {
        if (u > v || l > v || r < u)
            return -1e18;

        if (l >= u && r <= v)
            return seg[id];

        push(id);
        int m = (l + r) / 2;
        return max(get(id * 2, l, m, u, v), get(id * 2 + 1, m + 1, r, u, v));
    }
};

vector <pair <ll, ll>> compress(vector < pair <ll, ll>> &v) {
    vector <pair <ll, ll>> st;
    for (auto x : v) {
        if (st.empty() || st.back().f != x.f) {
            st.pb(x);
        } else {
            st[sz(st) - 1].s += x.s;
        }
    }
    return st;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll ans = 0;
    int n, m;
    cin >> n >> m;

    for (int i = 1; i <= n; i++) {
        cin >> A[i] >> S[i] >> P[i];
        SA[i] = SA[i - 1] + A[i];
    }

    for (int i = 1; i <= m; i++) {
        cin >> B[i] >> T[i] >> Q[i];
        SB[i] = SB[i - 1] + B[i];
    }

    for (int i = 1; i <= n; i++) {
        if (SA[i] > S[i])
            continue;

        ans += P[i];
        int id = upper_bound(SB, SB + 1 + m, S[i] - SA[i]) - SB - 1;
        if (id < m)
            pos[i - 1].pb({id + 1, -P[i]});
    }

    for (int i = 1; i <= m; i++) {
        if (SB[i] > T[i])
            continue;

        int id = upper_bound(SA, SA + 1 + n, T[i] - SB[i]) - SA - 1;
        pos[id].pb({i, Q[i]});
    }

    for (int i = 0; i <= n; i++) {
        sort(all(pos[i]));
        pos[i] = compress(pos[i]);
    }

    ST seg(m + 10);

    int lx = 0;
    for (int i = 0; i <= n; i++) {
        ll cur = 0;
        for (auto x : pos[i]) {
            cur += x.s;
        }

        if (sz(pos[i])) {
            lx = pos[i].back().f;
        } else {
            lx = 0;
        }

        vector <pair <ll, ll>> save;
        for (int j = sz(pos[i]) - 1; j >= 0; j--) {
            ll t = seg.get(1, 0, m, 0, pos[i][j].f) + cur;
            save.pb({pos[i][j].f, t});
            seg.upd(1, 0, m, pos[i][j].f, m, pos[i][j].s);
            cur -= pos[i][j].s;
        }

        for (auto x : save) {
            seg.point(1, 0, m, x.f, x.s);
        }
    }

    cout << seg.get(1, 0, m, lx, m) + ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 289 ms 86168 KB Output is correct
2 Correct 290 ms 90576 KB Output is correct
3 Correct 215 ms 89420 KB Output is correct
4 Correct 214 ms 84864 KB Output is correct
5 Correct 7 ms 35416 KB Output is correct
6 Correct 276 ms 87208 KB Output is correct
7 Correct 150 ms 74524 KB Output is correct
8 Correct 64 ms 49944 KB Output is correct
9 Correct 250 ms 90924 KB Output is correct
10 Correct 228 ms 79068 KB Output is correct
11 Correct 197 ms 82860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 35420 KB Output is correct
2 Correct 7 ms 35420 KB Output is correct
3 Correct 9 ms 35444 KB Output is correct
4 Correct 7 ms 35420 KB Output is correct
5 Correct 7 ms 35432 KB Output is correct
6 Correct 7 ms 35420 KB Output is correct
7 Correct 7 ms 35500 KB Output is correct
8 Correct 7 ms 35536 KB Output is correct
9 Correct 7 ms 35420 KB Output is correct
10 Correct 7 ms 35420 KB Output is correct
11 Correct 8 ms 35416 KB Output is correct
12 Correct 7 ms 35500 KB Output is correct
13 Correct 7 ms 35420 KB Output is correct
14 Correct 7 ms 35420 KB Output is correct
15 Correct 7 ms 35416 KB Output is correct
16 Correct 7 ms 35312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 35420 KB Output is correct
2 Correct 7 ms 35420 KB Output is correct
3 Correct 9 ms 35444 KB Output is correct
4 Correct 7 ms 35420 KB Output is correct
5 Correct 7 ms 35432 KB Output is correct
6 Correct 7 ms 35420 KB Output is correct
7 Correct 7 ms 35500 KB Output is correct
8 Correct 7 ms 35536 KB Output is correct
9 Correct 7 ms 35420 KB Output is correct
10 Correct 7 ms 35420 KB Output is correct
11 Correct 8 ms 35416 KB Output is correct
12 Correct 7 ms 35500 KB Output is correct
13 Correct 7 ms 35420 KB Output is correct
14 Correct 7 ms 35420 KB Output is correct
15 Correct 7 ms 35416 KB Output is correct
16 Correct 7 ms 35312 KB Output is correct
17 Correct 9 ms 37980 KB Output is correct
18 Correct 9 ms 37936 KB Output is correct
19 Correct 11 ms 37980 KB Output is correct
20 Correct 9 ms 35676 KB Output is correct
21 Correct 10 ms 38016 KB Output is correct
22 Correct 11 ms 37976 KB Output is correct
23 Correct 10 ms 37756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 35420 KB Output is correct
2 Correct 7 ms 35420 KB Output is correct
3 Correct 9 ms 35444 KB Output is correct
4 Correct 7 ms 35420 KB Output is correct
5 Correct 7 ms 35432 KB Output is correct
6 Correct 7 ms 35420 KB Output is correct
7 Correct 7 ms 35500 KB Output is correct
8 Correct 7 ms 35536 KB Output is correct
9 Correct 7 ms 35420 KB Output is correct
10 Correct 7 ms 35420 KB Output is correct
11 Correct 8 ms 35416 KB Output is correct
12 Correct 7 ms 35500 KB Output is correct
13 Correct 7 ms 35420 KB Output is correct
14 Correct 7 ms 35420 KB Output is correct
15 Correct 7 ms 35416 KB Output is correct
16 Correct 7 ms 35312 KB Output is correct
17 Correct 9 ms 37980 KB Output is correct
18 Correct 9 ms 37936 KB Output is correct
19 Correct 11 ms 37980 KB Output is correct
20 Correct 9 ms 35676 KB Output is correct
21 Correct 10 ms 38016 KB Output is correct
22 Correct 11 ms 37976 KB Output is correct
23 Correct 10 ms 37756 KB Output is correct
24 Correct 310 ms 84380 KB Output is correct
25 Correct 197 ms 86660 KB Output is correct
26 Correct 269 ms 85768 KB Output is correct
27 Correct 222 ms 80988 KB Output is correct
28 Correct 259 ms 82796 KB Output is correct
29 Correct 230 ms 85852 KB Output is correct
30 Correct 475 ms 85048 KB Output is correct
31 Correct 158 ms 71256 KB Output is correct
32 Correct 66 ms 51164 KB Output is correct
33 Correct 283 ms 79996 KB Output is correct
34 Correct 405 ms 83292 KB Output is correct
35 Correct 473 ms 79908 KB Output is correct
36 Correct 420 ms 79192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 35420 KB Output is correct
2 Correct 7 ms 35420 KB Output is correct
3 Correct 9 ms 35444 KB Output is correct
4 Correct 7 ms 35420 KB Output is correct
5 Correct 7 ms 35432 KB Output is correct
6 Correct 7 ms 35420 KB Output is correct
7 Correct 7 ms 35500 KB Output is correct
8 Correct 7 ms 35536 KB Output is correct
9 Correct 7 ms 35420 KB Output is correct
10 Correct 7 ms 35420 KB Output is correct
11 Correct 8 ms 35416 KB Output is correct
12 Correct 7 ms 35500 KB Output is correct
13 Correct 7 ms 35420 KB Output is correct
14 Correct 7 ms 35420 KB Output is correct
15 Correct 7 ms 35416 KB Output is correct
16 Correct 7 ms 35312 KB Output is correct
17 Correct 9 ms 37980 KB Output is correct
18 Correct 9 ms 37936 KB Output is correct
19 Correct 11 ms 37980 KB Output is correct
20 Correct 9 ms 35676 KB Output is correct
21 Correct 10 ms 38016 KB Output is correct
22 Correct 11 ms 37976 KB Output is correct
23 Correct 10 ms 37756 KB Output is correct
24 Correct 310 ms 84380 KB Output is correct
25 Correct 197 ms 86660 KB Output is correct
26 Correct 269 ms 85768 KB Output is correct
27 Correct 222 ms 80988 KB Output is correct
28 Correct 259 ms 82796 KB Output is correct
29 Correct 230 ms 85852 KB Output is correct
30 Correct 475 ms 85048 KB Output is correct
31 Correct 158 ms 71256 KB Output is correct
32 Correct 66 ms 51164 KB Output is correct
33 Correct 283 ms 79996 KB Output is correct
34 Correct 405 ms 83292 KB Output is correct
35 Correct 473 ms 79908 KB Output is correct
36 Correct 420 ms 79192 KB Output is correct
37 Correct 293 ms 88988 KB Output is correct
38 Correct 251 ms 82428 KB Output is correct
39 Correct 258 ms 84948 KB Output is correct
40 Correct 240 ms 84320 KB Output is correct
41 Correct 7 ms 35420 KB Output is correct
42 Correct 506 ms 89940 KB Output is correct
43 Correct 300 ms 82472 KB Output is correct
44 Correct 409 ms 86700 KB Output is correct
45 Correct 489 ms 82692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 35420 KB Output is correct
2 Correct 7 ms 35420 KB Output is correct
3 Correct 9 ms 35444 KB Output is correct
4 Correct 7 ms 35420 KB Output is correct
5 Correct 7 ms 35432 KB Output is correct
6 Correct 7 ms 35420 KB Output is correct
7 Correct 7 ms 35500 KB Output is correct
8 Correct 7 ms 35536 KB Output is correct
9 Correct 7 ms 35420 KB Output is correct
10 Correct 7 ms 35420 KB Output is correct
11 Correct 8 ms 35416 KB Output is correct
12 Correct 7 ms 35500 KB Output is correct
13 Correct 7 ms 35420 KB Output is correct
14 Correct 7 ms 35420 KB Output is correct
15 Correct 7 ms 35416 KB Output is correct
16 Correct 7 ms 35312 KB Output is correct
17 Correct 9 ms 37980 KB Output is correct
18 Correct 9 ms 37936 KB Output is correct
19 Correct 11 ms 37980 KB Output is correct
20 Correct 9 ms 35676 KB Output is correct
21 Correct 10 ms 38016 KB Output is correct
22 Correct 11 ms 37976 KB Output is correct
23 Correct 10 ms 37756 KB Output is correct
24 Correct 310 ms 84380 KB Output is correct
25 Correct 197 ms 86660 KB Output is correct
26 Correct 269 ms 85768 KB Output is correct
27 Correct 222 ms 80988 KB Output is correct
28 Correct 259 ms 82796 KB Output is correct
29 Correct 230 ms 85852 KB Output is correct
30 Correct 475 ms 85048 KB Output is correct
31 Correct 158 ms 71256 KB Output is correct
32 Correct 66 ms 51164 KB Output is correct
33 Correct 283 ms 79996 KB Output is correct
34 Correct 405 ms 83292 KB Output is correct
35 Correct 473 ms 79908 KB Output is correct
36 Correct 420 ms 79192 KB Output is correct
37 Correct 293 ms 88988 KB Output is correct
38 Correct 251 ms 82428 KB Output is correct
39 Correct 258 ms 84948 KB Output is correct
40 Correct 240 ms 84320 KB Output is correct
41 Correct 7 ms 35420 KB Output is correct
42 Correct 506 ms 89940 KB Output is correct
43 Correct 300 ms 82472 KB Output is correct
44 Correct 409 ms 86700 KB Output is correct
45 Correct 489 ms 82692 KB Output is correct
46 Correct 1515 ms 276308 KB Output is correct
47 Correct 1220 ms 251660 KB Output is correct
48 Correct 1235 ms 255112 KB Output is correct
49 Correct 1236 ms 254772 KB Output is correct
50 Correct 3293 ms 278604 KB Output is correct
51 Correct 1802 ms 246732 KB Output is correct
52 Correct 2305 ms 266620 KB Output is correct
53 Correct 3094 ms 246712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 289 ms 86168 KB Output is correct
2 Correct 290 ms 90576 KB Output is correct
3 Correct 215 ms 89420 KB Output is correct
4 Correct 214 ms 84864 KB Output is correct
5 Correct 7 ms 35416 KB Output is correct
6 Correct 276 ms 87208 KB Output is correct
7 Correct 150 ms 74524 KB Output is correct
8 Correct 64 ms 49944 KB Output is correct
9 Correct 250 ms 90924 KB Output is correct
10 Correct 228 ms 79068 KB Output is correct
11 Correct 197 ms 82860 KB Output is correct
12 Correct 7 ms 35420 KB Output is correct
13 Correct 7 ms 35420 KB Output is correct
14 Correct 9 ms 35444 KB Output is correct
15 Correct 7 ms 35420 KB Output is correct
16 Correct 7 ms 35432 KB Output is correct
17 Correct 7 ms 35420 KB Output is correct
18 Correct 7 ms 35500 KB Output is correct
19 Correct 7 ms 35536 KB Output is correct
20 Correct 7 ms 35420 KB Output is correct
21 Correct 7 ms 35420 KB Output is correct
22 Correct 8 ms 35416 KB Output is correct
23 Correct 7 ms 35500 KB Output is correct
24 Correct 7 ms 35420 KB Output is correct
25 Correct 7 ms 35420 KB Output is correct
26 Correct 7 ms 35416 KB Output is correct
27 Correct 7 ms 35312 KB Output is correct
28 Correct 9 ms 37980 KB Output is correct
29 Correct 9 ms 37936 KB Output is correct
30 Correct 11 ms 37980 KB Output is correct
31 Correct 9 ms 35676 KB Output is correct
32 Correct 10 ms 38016 KB Output is correct
33 Correct 11 ms 37976 KB Output is correct
34 Correct 10 ms 37756 KB Output is correct
35 Correct 310 ms 84380 KB Output is correct
36 Correct 197 ms 86660 KB Output is correct
37 Correct 269 ms 85768 KB Output is correct
38 Correct 222 ms 80988 KB Output is correct
39 Correct 259 ms 82796 KB Output is correct
40 Correct 230 ms 85852 KB Output is correct
41 Correct 475 ms 85048 KB Output is correct
42 Correct 158 ms 71256 KB Output is correct
43 Correct 66 ms 51164 KB Output is correct
44 Correct 283 ms 79996 KB Output is correct
45 Correct 405 ms 83292 KB Output is correct
46 Correct 473 ms 79908 KB Output is correct
47 Correct 420 ms 79192 KB Output is correct
48 Correct 293 ms 88988 KB Output is correct
49 Correct 251 ms 82428 KB Output is correct
50 Correct 258 ms 84948 KB Output is correct
51 Correct 240 ms 84320 KB Output is correct
52 Correct 7 ms 35420 KB Output is correct
53 Correct 506 ms 89940 KB Output is correct
54 Correct 300 ms 82472 KB Output is correct
55 Correct 409 ms 86700 KB Output is correct
56 Correct 489 ms 82692 KB Output is correct
57 Correct 288 ms 89896 KB Output is correct
58 Correct 234 ms 83288 KB Output is correct
59 Correct 250 ms 86840 KB Output is correct
60 Correct 257 ms 86776 KB Output is correct
61 Correct 488 ms 87500 KB Output is correct
62 Correct 7 ms 35416 KB Output is correct
63 Correct 487 ms 91092 KB Output is correct
64 Correct 309 ms 81240 KB Output is correct
65 Correct 416 ms 90328 KB Output is correct
66 Correct 480 ms 81716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 289 ms 86168 KB Output is correct
2 Correct 290 ms 90576 KB Output is correct
3 Correct 215 ms 89420 KB Output is correct
4 Correct 214 ms 84864 KB Output is correct
5 Correct 7 ms 35416 KB Output is correct
6 Correct 276 ms 87208 KB Output is correct
7 Correct 150 ms 74524 KB Output is correct
8 Correct 64 ms 49944 KB Output is correct
9 Correct 250 ms 90924 KB Output is correct
10 Correct 228 ms 79068 KB Output is correct
11 Correct 197 ms 82860 KB Output is correct
12 Correct 7 ms 35420 KB Output is correct
13 Correct 7 ms 35420 KB Output is correct
14 Correct 9 ms 35444 KB Output is correct
15 Correct 7 ms 35420 KB Output is correct
16 Correct 7 ms 35432 KB Output is correct
17 Correct 7 ms 35420 KB Output is correct
18 Correct 7 ms 35500 KB Output is correct
19 Correct 7 ms 35536 KB Output is correct
20 Correct 7 ms 35420 KB Output is correct
21 Correct 7 ms 35420 KB Output is correct
22 Correct 8 ms 35416 KB Output is correct
23 Correct 7 ms 35500 KB Output is correct
24 Correct 7 ms 35420 KB Output is correct
25 Correct 7 ms 35420 KB Output is correct
26 Correct 7 ms 35416 KB Output is correct
27 Correct 7 ms 35312 KB Output is correct
28 Correct 9 ms 37980 KB Output is correct
29 Correct 9 ms 37936 KB Output is correct
30 Correct 11 ms 37980 KB Output is correct
31 Correct 9 ms 35676 KB Output is correct
32 Correct 10 ms 38016 KB Output is correct
33 Correct 11 ms 37976 KB Output is correct
34 Correct 10 ms 37756 KB Output is correct
35 Correct 310 ms 84380 KB Output is correct
36 Correct 197 ms 86660 KB Output is correct
37 Correct 269 ms 85768 KB Output is correct
38 Correct 222 ms 80988 KB Output is correct
39 Correct 259 ms 82796 KB Output is correct
40 Correct 230 ms 85852 KB Output is correct
41 Correct 475 ms 85048 KB Output is correct
42 Correct 158 ms 71256 KB Output is correct
43 Correct 66 ms 51164 KB Output is correct
44 Correct 283 ms 79996 KB Output is correct
45 Correct 405 ms 83292 KB Output is correct
46 Correct 473 ms 79908 KB Output is correct
47 Correct 420 ms 79192 KB Output is correct
48 Correct 293 ms 88988 KB Output is correct
49 Correct 251 ms 82428 KB Output is correct
50 Correct 258 ms 84948 KB Output is correct
51 Correct 240 ms 84320 KB Output is correct
52 Correct 7 ms 35420 KB Output is correct
53 Correct 506 ms 89940 KB Output is correct
54 Correct 300 ms 82472 KB Output is correct
55 Correct 409 ms 86700 KB Output is correct
56 Correct 489 ms 82692 KB Output is correct
57 Correct 1515 ms 276308 KB Output is correct
58 Correct 1220 ms 251660 KB Output is correct
59 Correct 1235 ms 255112 KB Output is correct
60 Correct 1236 ms 254772 KB Output is correct
61 Correct 3293 ms 278604 KB Output is correct
62 Correct 1802 ms 246732 KB Output is correct
63 Correct 2305 ms 266620 KB Output is correct
64 Correct 3094 ms 246712 KB Output is correct
65 Correct 288 ms 89896 KB Output is correct
66 Correct 234 ms 83288 KB Output is correct
67 Correct 250 ms 86840 KB Output is correct
68 Correct 257 ms 86776 KB Output is correct
69 Correct 488 ms 87500 KB Output is correct
70 Correct 7 ms 35416 KB Output is correct
71 Correct 487 ms 91092 KB Output is correct
72 Correct 309 ms 81240 KB Output is correct
73 Correct 416 ms 90328 KB Output is correct
74 Correct 480 ms 81716 KB Output is correct
75 Correct 1487 ms 276780 KB Output is correct
76 Correct 1186 ms 252984 KB Output is correct
77 Correct 1251 ms 254948 KB Output is correct
78 Correct 1268 ms 254844 KB Output is correct
79 Correct 3348 ms 279116 KB Output is correct
80 Correct 1842 ms 242784 KB Output is correct
81 Correct 2413 ms 277420 KB Output is correct
82 Correct 3135 ms 246928 KB Output is correct
83 Correct 3087 ms 267712 KB Output is correct