Submission #976899

# Submission time Handle Problem Language Result Execution time Memory
976899 2024-05-07T08:40:03 Z zwezdinv Food Court (JOI21_foodcourt) C++17
24 / 100
467 ms 52308 KB
#include<bits/stdc++.h>
using namespace std;

using ll = long long;

const int N = 2.5e5 + 1;

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) {
            apply(node, x);
            return;
        }
        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);
    }

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

    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);
        }
    }
}

namespace ST2 {
    int tr[4 * N];

    void update(int k, int x, int node = 1, int l = 0, int r = N - 1) {
        if (l == r) {
            tr[node] += x;
            return;
        }
        int m = (l + r) / 2;
        if (k <= m) update(k, x, node << 1, l, m);
        else update(k, x, node << 1 | 1, m + 1, r);
        tr[node] = tr[node << 1] + tr[node << 1 | 1];
    }

    ll sm;
    int find_(int k, int node = 1, int l = 0, int r = N - 1) {
        if (l > k) return -1;
        if (r <= k) {
            if (tr[node] < sm) {
                sm -= tr[node];
                return -1;
            }
            if (l == r) return l;
        }
        int m = (l + r) / 2;
        int res = find_(k, node << 1 | 1, m + 1, r);
        if (res == -1) return find_(k, node << 1, l, m);
        return res;
    }
    int find(int k, ll sm_) {
        sm = sm_;
        return find_(k);
    }
}

int col[N];
bool to_ans[N];
vector<pair<int, ll>> upd[N], ev[N];
int ans[N];

int main() {
    cin.tie(nullptr)->sync_with_stdio(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);
            upd[l].emplace_back(i, b);
            upd[r + 1].emplace_back(i, -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;
            ev[a].emplace_back(i, ST::get(a) - b + 1);
            to_ans[i] = true;
        }
    }
    for (int i = 0; i < n; ++i) {
        for (auto [id, val] : upd[i]) {
            ST2::update(id, val);
        }
        for (auto [id, val] : ev[i]) {
            if (val <= 0) ans[id] = 0;
            else {
                int k = ST2::find(id, val);
                if (k != -1) ans[id] = col[k];
                else ans[id] = 0;
            }
        }
    }
    for (int i = 0; i < q; ++i) {
        if (to_ans[i]) {
            cout << ans[i] << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 22 ms 45392 KB Output is correct
2 Correct 12 ms 45660 KB Output is correct
3 Correct 16 ms 45508 KB Output is correct
4 Correct 14 ms 45660 KB Output is correct
5 Correct 11 ms 45660 KB Output is correct
6 Correct 11 ms 45656 KB Output is correct
7 Correct 11 ms 45676 KB Output is correct
8 Correct 12 ms 45660 KB Output is correct
9 Correct 12 ms 45672 KB Output is correct
10 Correct 14 ms 45660 KB Output is correct
11 Correct 12 ms 45660 KB Output is correct
12 Correct 12 ms 45588 KB Output is correct
13 Correct 10 ms 45660 KB Output is correct
14 Correct 11 ms 45588 KB Output is correct
15 Correct 14 ms 45588 KB Output is correct
16 Correct 11 ms 45660 KB Output is correct
17 Correct 11 ms 45404 KB Output is correct
18 Correct 12 ms 45612 KB Output is correct
19 Correct 12 ms 45660 KB Output is correct
20 Correct 12 ms 45588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 45392 KB Output is correct
2 Correct 12 ms 45660 KB Output is correct
3 Correct 16 ms 45508 KB Output is correct
4 Correct 14 ms 45660 KB Output is correct
5 Correct 11 ms 45660 KB Output is correct
6 Correct 11 ms 45656 KB Output is correct
7 Correct 11 ms 45676 KB Output is correct
8 Correct 12 ms 45660 KB Output is correct
9 Correct 12 ms 45672 KB Output is correct
10 Correct 14 ms 45660 KB Output is correct
11 Correct 12 ms 45660 KB Output is correct
12 Correct 12 ms 45588 KB Output is correct
13 Correct 10 ms 45660 KB Output is correct
14 Correct 11 ms 45588 KB Output is correct
15 Correct 14 ms 45588 KB Output is correct
16 Correct 11 ms 45660 KB Output is correct
17 Correct 11 ms 45404 KB Output is correct
18 Correct 12 ms 45612 KB Output is correct
19 Correct 12 ms 45660 KB Output is correct
20 Correct 12 ms 45588 KB Output is correct
21 Incorrect 12 ms 45660 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 102 ms 47488 KB Output is correct
2 Correct 125 ms 47956 KB Output is correct
3 Correct 104 ms 47576 KB Output is correct
4 Correct 98 ms 47452 KB Output is correct
5 Correct 98 ms 47976 KB Output is correct
6 Correct 107 ms 47932 KB Output is correct
7 Correct 49 ms 47048 KB Output is correct
8 Correct 50 ms 46848 KB Output is correct
9 Correct 98 ms 47720 KB Output is correct
10 Correct 118 ms 47432 KB Output is correct
11 Correct 105 ms 47676 KB Output is correct
12 Correct 107 ms 47440 KB Output is correct
13 Correct 85 ms 47956 KB Output is correct
14 Correct 90 ms 48104 KB Output is correct
15 Correct 96 ms 48824 KB Output is correct
16 Correct 96 ms 48624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 467 ms 52308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 45392 KB Output is correct
2 Correct 12 ms 45660 KB Output is correct
3 Correct 16 ms 45508 KB Output is correct
4 Correct 14 ms 45660 KB Output is correct
5 Correct 11 ms 45660 KB Output is correct
6 Correct 11 ms 45656 KB Output is correct
7 Correct 11 ms 45676 KB Output is correct
8 Correct 12 ms 45660 KB Output is correct
9 Correct 12 ms 45672 KB Output is correct
10 Correct 14 ms 45660 KB Output is correct
11 Correct 12 ms 45660 KB Output is correct
12 Correct 12 ms 45588 KB Output is correct
13 Correct 10 ms 45660 KB Output is correct
14 Correct 11 ms 45588 KB Output is correct
15 Correct 14 ms 45588 KB Output is correct
16 Correct 11 ms 45660 KB Output is correct
17 Correct 11 ms 45404 KB Output is correct
18 Correct 12 ms 45612 KB Output is correct
19 Correct 12 ms 45660 KB Output is correct
20 Correct 12 ms 45588 KB Output is correct
21 Correct 102 ms 47488 KB Output is correct
22 Correct 125 ms 47956 KB Output is correct
23 Correct 104 ms 47576 KB Output is correct
24 Correct 98 ms 47452 KB Output is correct
25 Correct 98 ms 47976 KB Output is correct
26 Correct 107 ms 47932 KB Output is correct
27 Correct 49 ms 47048 KB Output is correct
28 Correct 50 ms 46848 KB Output is correct
29 Correct 98 ms 47720 KB Output is correct
30 Correct 118 ms 47432 KB Output is correct
31 Correct 105 ms 47676 KB Output is correct
32 Correct 107 ms 47440 KB Output is correct
33 Correct 85 ms 47956 KB Output is correct
34 Correct 90 ms 48104 KB Output is correct
35 Correct 96 ms 48824 KB Output is correct
36 Correct 96 ms 48624 KB Output is correct
37 Correct 87 ms 47444 KB Output is correct
38 Correct 77 ms 47448 KB Output is correct
39 Correct 42 ms 46792 KB Output is correct
40 Correct 44 ms 46980 KB Output is correct
41 Correct 89 ms 47464 KB Output is correct
42 Correct 116 ms 47488 KB Output is correct
43 Correct 102 ms 47584 KB Output is correct
44 Correct 96 ms 47444 KB Output is correct
45 Correct 91 ms 47540 KB Output is correct
46 Correct 112 ms 47700 KB Output is correct
47 Correct 52 ms 47040 KB Output is correct
48 Correct 77 ms 47444 KB Output is correct
49 Correct 80 ms 46928 KB Output is correct
50 Correct 100 ms 47188 KB Output is correct
51 Correct 117 ms 47744 KB Output is correct
52 Correct 120 ms 47520 KB Output is correct
53 Correct 75 ms 48120 KB Output is correct
54 Correct 99 ms 48808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 47988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 45392 KB Output is correct
2 Correct 12 ms 45660 KB Output is correct
3 Correct 16 ms 45508 KB Output is correct
4 Correct 14 ms 45660 KB Output is correct
5 Correct 11 ms 45660 KB Output is correct
6 Correct 11 ms 45656 KB Output is correct
7 Correct 11 ms 45676 KB Output is correct
8 Correct 12 ms 45660 KB Output is correct
9 Correct 12 ms 45672 KB Output is correct
10 Correct 14 ms 45660 KB Output is correct
11 Correct 12 ms 45660 KB Output is correct
12 Correct 12 ms 45588 KB Output is correct
13 Correct 10 ms 45660 KB Output is correct
14 Correct 11 ms 45588 KB Output is correct
15 Correct 14 ms 45588 KB Output is correct
16 Correct 11 ms 45660 KB Output is correct
17 Correct 11 ms 45404 KB Output is correct
18 Correct 12 ms 45612 KB Output is correct
19 Correct 12 ms 45660 KB Output is correct
20 Correct 12 ms 45588 KB Output is correct
21 Incorrect 12 ms 45660 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 45392 KB Output is correct
2 Correct 12 ms 45660 KB Output is correct
3 Correct 16 ms 45508 KB Output is correct
4 Correct 14 ms 45660 KB Output is correct
5 Correct 11 ms 45660 KB Output is correct
6 Correct 11 ms 45656 KB Output is correct
7 Correct 11 ms 45676 KB Output is correct
8 Correct 12 ms 45660 KB Output is correct
9 Correct 12 ms 45672 KB Output is correct
10 Correct 14 ms 45660 KB Output is correct
11 Correct 12 ms 45660 KB Output is correct
12 Correct 12 ms 45588 KB Output is correct
13 Correct 10 ms 45660 KB Output is correct
14 Correct 11 ms 45588 KB Output is correct
15 Correct 14 ms 45588 KB Output is correct
16 Correct 11 ms 45660 KB Output is correct
17 Correct 11 ms 45404 KB Output is correct
18 Correct 12 ms 45612 KB Output is correct
19 Correct 12 ms 45660 KB Output is correct
20 Correct 12 ms 45588 KB Output is correct
21 Incorrect 12 ms 45660 KB Output isn't correct
22 Halted 0 ms 0 KB -