Submission #976861

# Submission time Handle Problem Language Result Execution time Memory
976861 2024-05-07T08:06:18 Z zwezdinv Food Court (JOI21_foodcourt) C++17
68 / 100
1000 ms 363984 KB
#include<bits/stdc++.h>
using namespace std;

using ll = long long;

const int N = 2.5e5;

namespace ST {
    ll mn[4 * N], s_mn[4 * N], upd[4 * N], upd_mn[4 * N];
    int cnt[4 * N];

    void apply(int node, ll x) {
        mn[node] += x;
        s_mn[node] += x;
        upd_mn[node] += x;
        upd[node] += x;
    }

    void apply_mn(int node, ll x) {
        upd_mn[node] = max(upd_mn[node], x);
        mn[node] = max(mn[node], upd_mn[node]);
    }

    void push(int node) {
        apply(node << 1, upd[node]);
        apply(node << 1 | 1, upd[node]);
        apply_mn(node << 1, upd_mn[node]);
        apply_mn(node << 1 | 1, upd_mn[node]);
        upd[node] = 0;
        upd_mn[node] = -1e17;
    }

    void pull(int node) {
        mn[node] = min(mn[node << 1], mn[node << 1 | 1]);
        cnt[node] = 0;
        if (mn[node << 1] == mn[node]) cnt[node] += cnt[node << 1];
        if (mn[node << 1 | 1] == mn[node]) cnt[node] += cnt[node << 1 | 1];
        s_mn[node] = 1e17;
        for (auto x : {mn[node << 1], s_mn[node << 1], mn[node << 1 | 1], s_mn[node << 1 | 1]}) {
            if (x != mn[node]) s_mn[node] = min(s_mn[node], x);
        }
    }

    void update(int ql, int qr, int x, int node = 1, int l = 0, int r = N - 1) {
        if (r < ql || qr < l) return;
        if (ql <= l && r <= qr) {
            // cout << 11 << ' ' << node << ' ' << l << ' ' << r << ' ' << ql << ' ' << qr << ' ' << x << ' ' << mn[node] << ' ' << s_mn[node] << ' ' << cnt[node] << endl;
            apply(node, x);
//            cout << l << ' ' << r << ' ' << mn[node] << ' ' << s_mn[node] << ' ' << cnt[node] << endl;
            return;
        }
//        cout << node << ' ' << l << ' ' << r << ' ' << mn[node] << ' ' << s_mn[node] << ' ' << cnt[node] << endl;
        push(node);
        int m = (l + r) / 2;
        update(ql, qr, x, node << 1, l, m);
        update(ql, qr, x, node << 1 | 1, m + 1, r);
        pull(node);
//        cout << l << ' ' << r << ' ' << mn[node] << ' ' << s_mn[node] << ' ' << cnt[node] << endl;
    }

    void fix(int node = 1, int l = 0, int r = N - 1) {
//        cout << l << ' ' << r << ' ' << mn[node] << ' ' << s_mn[node] << ' ' << cnt[node] << endl;
        if (mn[node] >= 0) return;
        if (s_mn[node] > 0) {
            apply_mn(node, 0);
//            cout << 11 << ' ' << l << ' ' << r << ' ' << mn[node] << ' ' << s_mn[node] << ' ' << cnt[node] << endl;
            return;
        }
        push(node);
        int m = (l + r) / 2;
        fix(node << 1, l, m);
        fix(node << 1 | 1, m + 1, r);
        pull(node);
//        cout << l << ' ' << r << ' ' << mn[node] << ' ' << s_mn[node] << ' ' << cnt[node] << endl;
    }

    ll get(int k, int node = 1, int l = 0, int r = N - 1) {
        if (l == r) return mn[node];
        push(node);
        int m = (l + r) / 2;
        if (k <= m) return get(k, node << 1, l, m);
        else return get(k, node << 1 | 1, m + 1, r);
    }

    void build(int node = 1, int l = 0, int r = N - 1) {
        if (l == r) {
            mn[node] = 0;
            cnt[node] = 1;
            s_mn[node] = 1e17;
            upd[node] = 0;
            upd_mn[node] = -1e17;
        } else {
            int m = (l + r) / 2;
            build(node << 1, l, m);
            build(node << 1 | 1, m + 1, r);
            pull(node);
        }
    }
}

const int B = 500;

vector<int> t_block[B], t_elem[N];
vector<ll> pref_block[B], pref_elem[N];
int col[N];

int main() {
    cin.tie(nullptr)->sync_with_stdio(0);

    for (int i = 0; i < B; ++i) pref_block[i] = {0};
    for (int i = 0; i < N; ++i) pref_elem[i] = {0};
    ST::build();

    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 0; i < q; ++i) {
        int t;
        cin >> t;
        if (t == 1) {
            int l, r;
            ll b;
            cin >> l >> r >> col[i] >> b;
            --l, --r;
            ST::update(l, r, b);
            for (; l <= r; l++) {
                if (l % B == 0 && l + B - 1 <= r) {
                    t_block[l / B].push_back(i);
                    pref_block[l / B].push_back(pref_block[l / B].back() + b);
                    l += B - 1;
                } else {
                    t_elem[l].push_back(i);
                    pref_elem[l].push_back(pref_elem[l].back() + b);
                }
            }
        } else if (t == 2) {
            int l, r;
            ll k;
            cin >> l >> r >> k;
            --l, --r;
            ST::update(l, r, -k);
            ST::fix();
        } else {
            int a;
            ll b;
            cin >> a >> b;
            --a;
            ll all = ST::get(a);
//            cerr << a << ' ' << all << endl;
            if (b > all) {
                cout << "0\n";
                continue;
            }
            b = all - b + 1;
//            cerr << i << ' ' << a << ' ' << b << endl;
            int L = -1, R = i;
            while (R - L > 1) {
                int M = (L + R) / 2;
                ll s_block = pref_block[a / B].back() - pref_block[a / B][upper_bound(t_block[a / B].begin(), t_block[a / B].end(), M) - t_block[a / B].begin()];
                // cerr << s_block << endl;
                ll s_elem = pref_elem[a].back() - pref_elem[a][upper_bound(t_elem[a].begin(), t_elem[a].end(), M) - t_elem[a].begin()];
                if (s_block + s_elem >= b) L = M;
                else R = M;
            }
            cout << col[R] << '\n';
        }
//        cerr << i << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 24 ms 51036 KB Output is correct
2 Correct 26 ms 52080 KB Output is correct
3 Correct 27 ms 53592 KB Output is correct
4 Correct 30 ms 56400 KB Output is correct
5 Correct 18 ms 47196 KB Output is correct
6 Correct 19 ms 47196 KB Output is correct
7 Correct 28 ms 54364 KB Output is correct
8 Correct 29 ms 54620 KB Output is correct
9 Correct 30 ms 54832 KB Output is correct
10 Correct 28 ms 54364 KB Output is correct
11 Correct 28 ms 54620 KB Output is correct
12 Correct 28 ms 54420 KB Output is correct
13 Correct 24 ms 51036 KB Output is correct
14 Correct 21 ms 47192 KB Output is correct
15 Correct 26 ms 52828 KB Output is correct
16 Correct 30 ms 59224 KB Output is correct
17 Correct 27 ms 52316 KB Output is correct
18 Correct 34 ms 54356 KB Output is correct
19 Correct 19 ms 47704 KB Output is correct
20 Correct 22 ms 47452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 51036 KB Output is correct
2 Correct 26 ms 52080 KB Output is correct
3 Correct 27 ms 53592 KB Output is correct
4 Correct 30 ms 56400 KB Output is correct
5 Correct 18 ms 47196 KB Output is correct
6 Correct 19 ms 47196 KB Output is correct
7 Correct 28 ms 54364 KB Output is correct
8 Correct 29 ms 54620 KB Output is correct
9 Correct 30 ms 54832 KB Output is correct
10 Correct 28 ms 54364 KB Output is correct
11 Correct 28 ms 54620 KB Output is correct
12 Correct 28 ms 54420 KB Output is correct
13 Correct 24 ms 51036 KB Output is correct
14 Correct 21 ms 47192 KB Output is correct
15 Correct 26 ms 52828 KB Output is correct
16 Correct 30 ms 59224 KB Output is correct
17 Correct 27 ms 52316 KB Output is correct
18 Correct 34 ms 54356 KB Output is correct
19 Correct 19 ms 47704 KB Output is correct
20 Correct 22 ms 47452 KB Output is correct
21 Correct 28 ms 51984 KB Output is correct
22 Correct 27 ms 52352 KB Output is correct
23 Correct 28 ms 54892 KB Output is correct
24 Correct 30 ms 56408 KB Output is correct
25 Correct 18 ms 47192 KB Output is correct
26 Correct 19 ms 47196 KB Output is correct
27 Correct 36 ms 54568 KB Output is correct
28 Correct 29 ms 54356 KB Output is correct
29 Correct 30 ms 54108 KB Output is correct
30 Correct 29 ms 54612 KB Output is correct
31 Correct 29 ms 54100 KB Output is correct
32 Correct 28 ms 54192 KB Output is correct
33 Correct 23 ms 49240 KB Output is correct
34 Correct 21 ms 47192 KB Output is correct
35 Correct 26 ms 53588 KB Output is correct
36 Correct 30 ms 59156 KB Output is correct
37 Correct 19 ms 47448 KB Output is correct
38 Correct 22 ms 47452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 50512 KB Output is correct
2 Correct 112 ms 51812 KB Output is correct
3 Correct 121 ms 52304 KB Output is correct
4 Correct 111 ms 52380 KB Output is correct
5 Correct 138 ms 54612 KB Output is correct
6 Correct 128 ms 54584 KB Output is correct
7 Correct 59 ms 47820 KB Output is correct
8 Correct 63 ms 48212 KB Output is correct
9 Correct 104 ms 50568 KB Output is correct
10 Correct 110 ms 50788 KB Output is correct
11 Correct 119 ms 50964 KB Output is correct
12 Correct 109 ms 50768 KB Output is correct
13 Correct 91 ms 51884 KB Output is correct
14 Correct 107 ms 52564 KB Output is correct
15 Correct 108 ms 54100 KB Output is correct
16 Correct 119 ms 54352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1116 ms 359452 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 51036 KB Output is correct
2 Correct 26 ms 52080 KB Output is correct
3 Correct 27 ms 53592 KB Output is correct
4 Correct 30 ms 56400 KB Output is correct
5 Correct 18 ms 47196 KB Output is correct
6 Correct 19 ms 47196 KB Output is correct
7 Correct 28 ms 54364 KB Output is correct
8 Correct 29 ms 54620 KB Output is correct
9 Correct 30 ms 54832 KB Output is correct
10 Correct 28 ms 54364 KB Output is correct
11 Correct 28 ms 54620 KB Output is correct
12 Correct 28 ms 54420 KB Output is correct
13 Correct 24 ms 51036 KB Output is correct
14 Correct 21 ms 47192 KB Output is correct
15 Correct 26 ms 52828 KB Output is correct
16 Correct 30 ms 59224 KB Output is correct
17 Correct 27 ms 52316 KB Output is correct
18 Correct 34 ms 54356 KB Output is correct
19 Correct 19 ms 47704 KB Output is correct
20 Correct 22 ms 47452 KB Output is correct
21 Correct 105 ms 50512 KB Output is correct
22 Correct 112 ms 51812 KB Output is correct
23 Correct 121 ms 52304 KB Output is correct
24 Correct 111 ms 52380 KB Output is correct
25 Correct 138 ms 54612 KB Output is correct
26 Correct 128 ms 54584 KB Output is correct
27 Correct 59 ms 47820 KB Output is correct
28 Correct 63 ms 48212 KB Output is correct
29 Correct 104 ms 50568 KB Output is correct
30 Correct 110 ms 50788 KB Output is correct
31 Correct 119 ms 50964 KB Output is correct
32 Correct 109 ms 50768 KB Output is correct
33 Correct 91 ms 51884 KB Output is correct
34 Correct 107 ms 52564 KB Output is correct
35 Correct 108 ms 54100 KB Output is correct
36 Correct 119 ms 54352 KB Output is correct
37 Correct 530 ms 230928 KB Output is correct
38 Correct 656 ms 299596 KB Output is correct
39 Correct 51 ms 47948 KB Output is correct
40 Correct 56 ms 48212 KB Output is correct
41 Correct 621 ms 286160 KB Output is correct
42 Correct 668 ms 286820 KB Output is correct
43 Correct 663 ms 287268 KB Output is correct
44 Correct 680 ms 286592 KB Output is correct
45 Correct 685 ms 286240 KB Output is correct
46 Correct 686 ms 287816 KB Output is correct
47 Correct 111 ms 87380 KB Output is correct
48 Correct 461 ms 274408 KB Output is correct
49 Correct 431 ms 221280 KB Output is correct
50 Correct 574 ms 260432 KB Output is correct
51 Correct 724 ms 297212 KB Output is correct
52 Correct 698 ms 297436 KB Output is correct
53 Correct 94 ms 53076 KB Output is correct
54 Correct 120 ms 54504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 709 ms 318292 KB Output is correct
2 Correct 766 ms 350836 KB Output is correct
3 Correct 843 ms 356272 KB Output is correct
4 Correct 575 ms 271252 KB Output is correct
5 Correct 730 ms 321304 KB Output is correct
6 Correct 874 ms 363984 KB Output is correct
7 Correct 68 ms 48076 KB Output is correct
8 Correct 64 ms 48328 KB Output is correct
9 Correct 163 ms 98168 KB Output is correct
10 Correct 432 ms 275216 KB Output is correct
11 Correct 712 ms 359524 KB Output is correct
12 Correct 697 ms 358656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 51036 KB Output is correct
2 Correct 26 ms 52080 KB Output is correct
3 Correct 27 ms 53592 KB Output is correct
4 Correct 30 ms 56400 KB Output is correct
5 Correct 18 ms 47196 KB Output is correct
6 Correct 19 ms 47196 KB Output is correct
7 Correct 28 ms 54364 KB Output is correct
8 Correct 29 ms 54620 KB Output is correct
9 Correct 30 ms 54832 KB Output is correct
10 Correct 28 ms 54364 KB Output is correct
11 Correct 28 ms 54620 KB Output is correct
12 Correct 28 ms 54420 KB Output is correct
13 Correct 24 ms 51036 KB Output is correct
14 Correct 21 ms 47192 KB Output is correct
15 Correct 26 ms 52828 KB Output is correct
16 Correct 30 ms 59224 KB Output is correct
17 Correct 27 ms 52316 KB Output is correct
18 Correct 34 ms 54356 KB Output is correct
19 Correct 19 ms 47704 KB Output is correct
20 Correct 22 ms 47452 KB Output is correct
21 Correct 28 ms 51984 KB Output is correct
22 Correct 27 ms 52352 KB Output is correct
23 Correct 28 ms 54892 KB Output is correct
24 Correct 30 ms 56408 KB Output is correct
25 Correct 18 ms 47192 KB Output is correct
26 Correct 19 ms 47196 KB Output is correct
27 Correct 36 ms 54568 KB Output is correct
28 Correct 29 ms 54356 KB Output is correct
29 Correct 30 ms 54108 KB Output is correct
30 Correct 29 ms 54612 KB Output is correct
31 Correct 29 ms 54100 KB Output is correct
32 Correct 28 ms 54192 KB Output is correct
33 Correct 23 ms 49240 KB Output is correct
34 Correct 21 ms 47192 KB Output is correct
35 Correct 26 ms 53588 KB Output is correct
36 Correct 30 ms 59156 KB Output is correct
37 Correct 19 ms 47448 KB Output is correct
38 Correct 22 ms 47452 KB Output is correct
39 Correct 105 ms 50512 KB Output is correct
40 Correct 112 ms 51812 KB Output is correct
41 Correct 121 ms 52304 KB Output is correct
42 Correct 111 ms 52380 KB Output is correct
43 Correct 138 ms 54612 KB Output is correct
44 Correct 128 ms 54584 KB Output is correct
45 Correct 59 ms 47820 KB Output is correct
46 Correct 63 ms 48212 KB Output is correct
47 Correct 104 ms 50568 KB Output is correct
48 Correct 110 ms 50788 KB Output is correct
49 Correct 119 ms 50964 KB Output is correct
50 Correct 109 ms 50768 KB Output is correct
51 Correct 91 ms 51884 KB Output is correct
52 Correct 107 ms 52564 KB Output is correct
53 Correct 108 ms 54100 KB Output is correct
54 Correct 119 ms 54352 KB Output is correct
55 Correct 530 ms 230928 KB Output is correct
56 Correct 656 ms 299596 KB Output is correct
57 Correct 51 ms 47948 KB Output is correct
58 Correct 56 ms 48212 KB Output is correct
59 Correct 621 ms 286160 KB Output is correct
60 Correct 668 ms 286820 KB Output is correct
61 Correct 663 ms 287268 KB Output is correct
62 Correct 680 ms 286592 KB Output is correct
63 Correct 685 ms 286240 KB Output is correct
64 Correct 686 ms 287816 KB Output is correct
65 Correct 111 ms 87380 KB Output is correct
66 Correct 461 ms 274408 KB Output is correct
67 Correct 431 ms 221280 KB Output is correct
68 Correct 574 ms 260432 KB Output is correct
69 Correct 724 ms 297212 KB Output is correct
70 Correct 698 ms 297436 KB Output is correct
71 Correct 94 ms 53076 KB Output is correct
72 Correct 120 ms 54504 KB Output is correct
73 Correct 709 ms 318292 KB Output is correct
74 Correct 766 ms 350836 KB Output is correct
75 Correct 843 ms 356272 KB Output is correct
76 Correct 575 ms 271252 KB Output is correct
77 Correct 730 ms 321304 KB Output is correct
78 Correct 874 ms 363984 KB Output is correct
79 Correct 68 ms 48076 KB Output is correct
80 Correct 64 ms 48328 KB Output is correct
81 Correct 163 ms 98168 KB Output is correct
82 Correct 432 ms 275216 KB Output is correct
83 Correct 712 ms 359524 KB Output is correct
84 Correct 697 ms 358656 KB Output is correct
85 Correct 499 ms 229476 KB Output is correct
86 Correct 589 ms 256204 KB Output is correct
87 Correct 727 ms 325028 KB Output is correct
88 Correct 814 ms 362304 KB Output is correct
89 Correct 408 ms 198996 KB Output is correct
90 Correct 656 ms 288892 KB Output is correct
91 Correct 493 ms 239332 KB Output is correct
92 Correct 442 ms 228064 KB Output is correct
93 Correct 653 ms 287976 KB Output is correct
94 Correct 643 ms 286992 KB Output is correct
95 Correct 607 ms 283132 KB Output is correct
96 Correct 695 ms 289224 KB Output is correct
97 Correct 658 ms 287788 KB Output is correct
98 Correct 663 ms 247768 KB Output is correct
99 Correct 130 ms 87500 KB Output is correct
100 Correct 399 ms 246520 KB Output is correct
101 Correct 504 ms 273756 KB Output is correct
102 Correct 346 ms 153104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 51036 KB Output is correct
2 Correct 26 ms 52080 KB Output is correct
3 Correct 27 ms 53592 KB Output is correct
4 Correct 30 ms 56400 KB Output is correct
5 Correct 18 ms 47196 KB Output is correct
6 Correct 19 ms 47196 KB Output is correct
7 Correct 28 ms 54364 KB Output is correct
8 Correct 29 ms 54620 KB Output is correct
9 Correct 30 ms 54832 KB Output is correct
10 Correct 28 ms 54364 KB Output is correct
11 Correct 28 ms 54620 KB Output is correct
12 Correct 28 ms 54420 KB Output is correct
13 Correct 24 ms 51036 KB Output is correct
14 Correct 21 ms 47192 KB Output is correct
15 Correct 26 ms 52828 KB Output is correct
16 Correct 30 ms 59224 KB Output is correct
17 Correct 27 ms 52316 KB Output is correct
18 Correct 34 ms 54356 KB Output is correct
19 Correct 19 ms 47704 KB Output is correct
20 Correct 22 ms 47452 KB Output is correct
21 Correct 28 ms 51984 KB Output is correct
22 Correct 27 ms 52352 KB Output is correct
23 Correct 28 ms 54892 KB Output is correct
24 Correct 30 ms 56408 KB Output is correct
25 Correct 18 ms 47192 KB Output is correct
26 Correct 19 ms 47196 KB Output is correct
27 Correct 36 ms 54568 KB Output is correct
28 Correct 29 ms 54356 KB Output is correct
29 Correct 30 ms 54108 KB Output is correct
30 Correct 29 ms 54612 KB Output is correct
31 Correct 29 ms 54100 KB Output is correct
32 Correct 28 ms 54192 KB Output is correct
33 Correct 23 ms 49240 KB Output is correct
34 Correct 21 ms 47192 KB Output is correct
35 Correct 26 ms 53588 KB Output is correct
36 Correct 30 ms 59156 KB Output is correct
37 Correct 19 ms 47448 KB Output is correct
38 Correct 22 ms 47452 KB Output is correct
39 Correct 105 ms 50512 KB Output is correct
40 Correct 112 ms 51812 KB Output is correct
41 Correct 121 ms 52304 KB Output is correct
42 Correct 111 ms 52380 KB Output is correct
43 Correct 138 ms 54612 KB Output is correct
44 Correct 128 ms 54584 KB Output is correct
45 Correct 59 ms 47820 KB Output is correct
46 Correct 63 ms 48212 KB Output is correct
47 Correct 104 ms 50568 KB Output is correct
48 Correct 110 ms 50788 KB Output is correct
49 Correct 119 ms 50964 KB Output is correct
50 Correct 109 ms 50768 KB Output is correct
51 Correct 91 ms 51884 KB Output is correct
52 Correct 107 ms 52564 KB Output is correct
53 Correct 108 ms 54100 KB Output is correct
54 Correct 119 ms 54352 KB Output is correct
55 Execution timed out 1116 ms 359452 KB Time limit exceeded
56 Halted 0 ms 0 KB -