답안 #944602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944602 2024-03-13T01:38:08 Z LOLOLO Two Dishes (JOI19_dishes) C++17
65 / 100
792 ms 64900 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 = 2e5 + 10;
ll A[N], B[N], SA[N], SB[N], S[N], T[N], Q[N], P[N];
vector <pair <ll, ll>> pos[N];
ll lim = -1e16;

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

    void push(int id, int l, int r) {
        seg[id] = max(seg[id] + laz[id], ass[id]);
        if (l == r) {
            laz[id] = 0;
            ass[id] = lim;
            return;
        }

        ll t = laz[id];
        ass[id * 2] = max(ass[id * 2] + t, ass[id]);
        ass[id * 2 + 1] = max(ass[id * 2 + 1] + t, ass[id]);
        laz[id * 2] += t;
        laz[id * 2 + 1] += t;
        laz[id] = 0;
        ass[id] = lim;
    }

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

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

        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 range(int id, int l, int r, int u, int v, ll val) {
        push(id, l, r);
        if (l > v || r < u)
            return;

        if (l >= u && r <= v) {
            ass[id] = val;
            push(id, l, r);
            return;
        }

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

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

        if (l >= u && r <= v)
            return seg[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;
        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 = 1; i <= n; i++) {
        sort(all(pos[i]));
        pos[i] = compress(pos[i]);
    }

    ST seg(m);

    for (int i = 0; i <= n; i++) {
        for (auto x : pos[i]) {
            seg.upd(1, 0, m, x.f, m, x.s);
        }
        
        reverse(all(pos[i]));
        int lx = m;
        for (auto x : pos[i]) {
            seg.range(1, 0, m, x.f, lx, seg.get(1, 0, m, 0, x.f));
            lx = x.f -1;
        }
    }

    cout << seg.get(1, 0, m, m, m) + ans << '\n';
    return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 400 ms 58368 KB Output is correct
2 Correct 425 ms 61032 KB Output is correct
3 Correct 321 ms 62720 KB Output is correct
4 Correct 270 ms 57852 KB Output is correct
5 Correct 2 ms 12888 KB Output is correct
6 Correct 379 ms 58332 KB Output is correct
7 Correct 232 ms 51752 KB Output is correct
8 Correct 74 ms 29080 KB Output is correct
9 Correct 329 ms 64900 KB Output is correct
10 Correct 334 ms 54500 KB Output is correct
11 Correct 318 ms 61464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12928 KB Output is correct
3 Correct 2 ms 12888 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 2 ms 12892 KB Output is correct
6 Correct 2 ms 12932 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 3 ms 12928 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 3 ms 12892 KB Output is correct
12 Correct 2 ms 12932 KB Output is correct
13 Correct 3 ms 12892 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12928 KB Output is correct
3 Correct 2 ms 12888 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 2 ms 12892 KB Output is correct
6 Correct 2 ms 12932 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 3 ms 12928 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 3 ms 12892 KB Output is correct
12 Correct 2 ms 12932 KB Output is correct
13 Correct 3 ms 12892 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
17 Correct 5 ms 13400 KB Output is correct
18 Correct 5 ms 13400 KB Output is correct
19 Correct 6 ms 13404 KB Output is correct
20 Correct 5 ms 13404 KB Output is correct
21 Correct 6 ms 13656 KB Output is correct
22 Correct 9 ms 13200 KB Output is correct
23 Correct 6 ms 13400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12928 KB Output is correct
3 Correct 2 ms 12888 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 2 ms 12892 KB Output is correct
6 Correct 2 ms 12932 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 3 ms 12928 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 3 ms 12892 KB Output is correct
12 Correct 2 ms 12932 KB Output is correct
13 Correct 3 ms 12892 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
17 Correct 5 ms 13400 KB Output is correct
18 Correct 5 ms 13400 KB Output is correct
19 Correct 6 ms 13404 KB Output is correct
20 Correct 5 ms 13404 KB Output is correct
21 Correct 6 ms 13656 KB Output is correct
22 Correct 9 ms 13200 KB Output is correct
23 Correct 6 ms 13400 KB Output is correct
24 Correct 569 ms 52888 KB Output is correct
25 Correct 317 ms 57128 KB Output is correct
26 Correct 428 ms 53656 KB Output is correct
27 Correct 317 ms 56408 KB Output is correct
28 Correct 435 ms 55872 KB Output is correct
29 Correct 309 ms 61700 KB Output is correct
30 Correct 734 ms 59140 KB Output is correct
31 Correct 255 ms 42352 KB Output is correct
32 Correct 79 ms 27732 KB Output is correct
33 Correct 411 ms 51664 KB Output is correct
34 Correct 589 ms 58700 KB Output is correct
35 Correct 792 ms 52364 KB Output is correct
36 Correct 701 ms 54460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12928 KB Output is correct
3 Correct 2 ms 12888 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 2 ms 12892 KB Output is correct
6 Correct 2 ms 12932 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 3 ms 12928 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 3 ms 12892 KB Output is correct
12 Correct 2 ms 12932 KB Output is correct
13 Correct 3 ms 12892 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
17 Correct 5 ms 13400 KB Output is correct
18 Correct 5 ms 13400 KB Output is correct
19 Correct 6 ms 13404 KB Output is correct
20 Correct 5 ms 13404 KB Output is correct
21 Correct 6 ms 13656 KB Output is correct
22 Correct 9 ms 13200 KB Output is correct
23 Correct 6 ms 13400 KB Output is correct
24 Correct 569 ms 52888 KB Output is correct
25 Correct 317 ms 57128 KB Output is correct
26 Correct 428 ms 53656 KB Output is correct
27 Correct 317 ms 56408 KB Output is correct
28 Correct 435 ms 55872 KB Output is correct
29 Correct 309 ms 61700 KB Output is correct
30 Correct 734 ms 59140 KB Output is correct
31 Correct 255 ms 42352 KB Output is correct
32 Correct 79 ms 27732 KB Output is correct
33 Correct 411 ms 51664 KB Output is correct
34 Correct 589 ms 58700 KB Output is correct
35 Correct 792 ms 52364 KB Output is correct
36 Correct 701 ms 54460 KB Output is correct
37 Correct 421 ms 58568 KB Output is correct
38 Correct 351 ms 58384 KB Output is correct
39 Correct 329 ms 59176 KB Output is correct
40 Correct 345 ms 58440 KB Output is correct
41 Correct 2 ms 12892 KB Output is correct
42 Correct 759 ms 61056 KB Output is correct
43 Correct 450 ms 57076 KB Output is correct
44 Correct 673 ms 58672 KB Output is correct
45 Correct 772 ms 57540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12928 KB Output is correct
3 Correct 2 ms 12888 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 2 ms 12892 KB Output is correct
6 Correct 2 ms 12932 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 3 ms 12928 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 3 ms 12892 KB Output is correct
12 Correct 2 ms 12932 KB Output is correct
13 Correct 3 ms 12892 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
17 Correct 5 ms 13400 KB Output is correct
18 Correct 5 ms 13400 KB Output is correct
19 Correct 6 ms 13404 KB Output is correct
20 Correct 5 ms 13404 KB Output is correct
21 Correct 6 ms 13656 KB Output is correct
22 Correct 9 ms 13200 KB Output is correct
23 Correct 6 ms 13400 KB Output is correct
24 Correct 569 ms 52888 KB Output is correct
25 Correct 317 ms 57128 KB Output is correct
26 Correct 428 ms 53656 KB Output is correct
27 Correct 317 ms 56408 KB Output is correct
28 Correct 435 ms 55872 KB Output is correct
29 Correct 309 ms 61700 KB Output is correct
30 Correct 734 ms 59140 KB Output is correct
31 Correct 255 ms 42352 KB Output is correct
32 Correct 79 ms 27732 KB Output is correct
33 Correct 411 ms 51664 KB Output is correct
34 Correct 589 ms 58700 KB Output is correct
35 Correct 792 ms 52364 KB Output is correct
36 Correct 701 ms 54460 KB Output is correct
37 Correct 421 ms 58568 KB Output is correct
38 Correct 351 ms 58384 KB Output is correct
39 Correct 329 ms 59176 KB Output is correct
40 Correct 345 ms 58440 KB Output is correct
41 Correct 2 ms 12892 KB Output is correct
42 Correct 759 ms 61056 KB Output is correct
43 Correct 450 ms 57076 KB Output is correct
44 Correct 673 ms 58672 KB Output is correct
45 Correct 772 ms 57540 KB Output is correct
46 Runtime error 101 ms 36948 KB Execution killed with signal 11
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 400 ms 58368 KB Output is correct
2 Correct 425 ms 61032 KB Output is correct
3 Correct 321 ms 62720 KB Output is correct
4 Correct 270 ms 57852 KB Output is correct
5 Correct 2 ms 12888 KB Output is correct
6 Correct 379 ms 58332 KB Output is correct
7 Correct 232 ms 51752 KB Output is correct
8 Correct 74 ms 29080 KB Output is correct
9 Correct 329 ms 64900 KB Output is correct
10 Correct 334 ms 54500 KB Output is correct
11 Correct 318 ms 61464 KB Output is correct
12 Correct 2 ms 12892 KB Output is correct
13 Correct 2 ms 12928 KB Output is correct
14 Correct 2 ms 12888 KB Output is correct
15 Correct 2 ms 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
17 Correct 2 ms 12932 KB Output is correct
18 Correct 2 ms 12892 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
20 Correct 3 ms 12928 KB Output is correct
21 Correct 2 ms 12892 KB Output is correct
22 Correct 3 ms 12892 KB Output is correct
23 Correct 2 ms 12932 KB Output is correct
24 Correct 3 ms 12892 KB Output is correct
25 Correct 2 ms 12892 KB Output is correct
26 Correct 3 ms 12892 KB Output is correct
27 Correct 2 ms 12892 KB Output is correct
28 Correct 5 ms 13400 KB Output is correct
29 Correct 5 ms 13400 KB Output is correct
30 Correct 6 ms 13404 KB Output is correct
31 Correct 5 ms 13404 KB Output is correct
32 Correct 6 ms 13656 KB Output is correct
33 Correct 9 ms 13200 KB Output is correct
34 Correct 6 ms 13400 KB Output is correct
35 Correct 569 ms 52888 KB Output is correct
36 Correct 317 ms 57128 KB Output is correct
37 Correct 428 ms 53656 KB Output is correct
38 Correct 317 ms 56408 KB Output is correct
39 Correct 435 ms 55872 KB Output is correct
40 Correct 309 ms 61700 KB Output is correct
41 Correct 734 ms 59140 KB Output is correct
42 Correct 255 ms 42352 KB Output is correct
43 Correct 79 ms 27732 KB Output is correct
44 Correct 411 ms 51664 KB Output is correct
45 Correct 589 ms 58700 KB Output is correct
46 Correct 792 ms 52364 KB Output is correct
47 Correct 701 ms 54460 KB Output is correct
48 Correct 421 ms 58568 KB Output is correct
49 Correct 351 ms 58384 KB Output is correct
50 Correct 329 ms 59176 KB Output is correct
51 Correct 345 ms 58440 KB Output is correct
52 Correct 2 ms 12892 KB Output is correct
53 Correct 759 ms 61056 KB Output is correct
54 Correct 450 ms 57076 KB Output is correct
55 Correct 673 ms 58672 KB Output is correct
56 Correct 772 ms 57540 KB Output is correct
57 Incorrect 479 ms 59032 KB Output isn't correct
58 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 400 ms 58368 KB Output is correct
2 Correct 425 ms 61032 KB Output is correct
3 Correct 321 ms 62720 KB Output is correct
4 Correct 270 ms 57852 KB Output is correct
5 Correct 2 ms 12888 KB Output is correct
6 Correct 379 ms 58332 KB Output is correct
7 Correct 232 ms 51752 KB Output is correct
8 Correct 74 ms 29080 KB Output is correct
9 Correct 329 ms 64900 KB Output is correct
10 Correct 334 ms 54500 KB Output is correct
11 Correct 318 ms 61464 KB Output is correct
12 Correct 2 ms 12892 KB Output is correct
13 Correct 2 ms 12928 KB Output is correct
14 Correct 2 ms 12888 KB Output is correct
15 Correct 2 ms 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
17 Correct 2 ms 12932 KB Output is correct
18 Correct 2 ms 12892 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
20 Correct 3 ms 12928 KB Output is correct
21 Correct 2 ms 12892 KB Output is correct
22 Correct 3 ms 12892 KB Output is correct
23 Correct 2 ms 12932 KB Output is correct
24 Correct 3 ms 12892 KB Output is correct
25 Correct 2 ms 12892 KB Output is correct
26 Correct 3 ms 12892 KB Output is correct
27 Correct 2 ms 12892 KB Output is correct
28 Correct 5 ms 13400 KB Output is correct
29 Correct 5 ms 13400 KB Output is correct
30 Correct 6 ms 13404 KB Output is correct
31 Correct 5 ms 13404 KB Output is correct
32 Correct 6 ms 13656 KB Output is correct
33 Correct 9 ms 13200 KB Output is correct
34 Correct 6 ms 13400 KB Output is correct
35 Correct 569 ms 52888 KB Output is correct
36 Correct 317 ms 57128 KB Output is correct
37 Correct 428 ms 53656 KB Output is correct
38 Correct 317 ms 56408 KB Output is correct
39 Correct 435 ms 55872 KB Output is correct
40 Correct 309 ms 61700 KB Output is correct
41 Correct 734 ms 59140 KB Output is correct
42 Correct 255 ms 42352 KB Output is correct
43 Correct 79 ms 27732 KB Output is correct
44 Correct 411 ms 51664 KB Output is correct
45 Correct 589 ms 58700 KB Output is correct
46 Correct 792 ms 52364 KB Output is correct
47 Correct 701 ms 54460 KB Output is correct
48 Correct 421 ms 58568 KB Output is correct
49 Correct 351 ms 58384 KB Output is correct
50 Correct 329 ms 59176 KB Output is correct
51 Correct 345 ms 58440 KB Output is correct
52 Correct 2 ms 12892 KB Output is correct
53 Correct 759 ms 61056 KB Output is correct
54 Correct 450 ms 57076 KB Output is correct
55 Correct 673 ms 58672 KB Output is correct
56 Correct 772 ms 57540 KB Output is correct
57 Runtime error 101 ms 36948 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -