Submission #976896

# Submission time Handle Problem Language Result Execution time Memory
976896 2024-05-07T08:39:08 Z zwezdinv Food Court (JOI21_foodcourt) C++17
24 / 100
407 ms 52196 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);
                ans[id] = col[k];
            }
        }
    }
    for (int i = 0; i < q; ++i) {
        if (to_ans[i]) {
            cout << ans[i] << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 45656 KB Output is correct
2 Correct 12 ms 45660 KB Output is correct
3 Correct 11 ms 45608 KB Output is correct
4 Correct 12 ms 45660 KB Output is correct
5 Correct 11 ms 45584 KB Output is correct
6 Correct 10 ms 45660 KB Output is correct
7 Correct 12 ms 45672 KB Output is correct
8 Correct 13 ms 45660 KB Output is correct
9 Correct 12 ms 45660 KB Output is correct
10 Correct 12 ms 45660 KB Output is correct
11 Correct 12 ms 45572 KB Output is correct
12 Correct 12 ms 45660 KB Output is correct
13 Correct 12 ms 45660 KB Output is correct
14 Correct 11 ms 45660 KB Output is correct
15 Correct 11 ms 45404 KB Output is correct
16 Correct 11 ms 45656 KB Output is correct
17 Correct 11 ms 45404 KB Output is correct
18 Correct 12 ms 45660 KB Output is correct
19 Correct 12 ms 45672 KB Output is correct
20 Correct 12 ms 45656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 45656 KB Output is correct
2 Correct 12 ms 45660 KB Output is correct
3 Correct 11 ms 45608 KB Output is correct
4 Correct 12 ms 45660 KB Output is correct
5 Correct 11 ms 45584 KB Output is correct
6 Correct 10 ms 45660 KB Output is correct
7 Correct 12 ms 45672 KB Output is correct
8 Correct 13 ms 45660 KB Output is correct
9 Correct 12 ms 45660 KB Output is correct
10 Correct 12 ms 45660 KB Output is correct
11 Correct 12 ms 45572 KB Output is correct
12 Correct 12 ms 45660 KB Output is correct
13 Correct 12 ms 45660 KB Output is correct
14 Correct 11 ms 45660 KB Output is correct
15 Correct 11 ms 45404 KB Output is correct
16 Correct 11 ms 45656 KB Output is correct
17 Correct 11 ms 45404 KB Output is correct
18 Correct 12 ms 45660 KB Output is correct
19 Correct 12 ms 45672 KB Output is correct
20 Correct 12 ms 45656 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 113 ms 47444 KB Output is correct
2 Correct 112 ms 47892 KB Output is correct
3 Correct 105 ms 47444 KB Output is correct
4 Correct 96 ms 47556 KB Output is correct
5 Correct 115 ms 48008 KB Output is correct
6 Correct 101 ms 47760 KB Output is correct
7 Correct 53 ms 47044 KB Output is correct
8 Correct 50 ms 47080 KB Output is correct
9 Correct 95 ms 47388 KB Output is correct
10 Correct 110 ms 47768 KB Output is correct
11 Correct 99 ms 47444 KB Output is correct
12 Correct 104 ms 47444 KB Output is correct
13 Correct 80 ms 47952 KB Output is correct
14 Correct 119 ms 48168 KB Output is correct
15 Correct 93 ms 48712 KB Output is correct
16 Correct 97 ms 48724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 407 ms 52196 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 45656 KB Output is correct
2 Correct 12 ms 45660 KB Output is correct
3 Correct 11 ms 45608 KB Output is correct
4 Correct 12 ms 45660 KB Output is correct
5 Correct 11 ms 45584 KB Output is correct
6 Correct 10 ms 45660 KB Output is correct
7 Correct 12 ms 45672 KB Output is correct
8 Correct 13 ms 45660 KB Output is correct
9 Correct 12 ms 45660 KB Output is correct
10 Correct 12 ms 45660 KB Output is correct
11 Correct 12 ms 45572 KB Output is correct
12 Correct 12 ms 45660 KB Output is correct
13 Correct 12 ms 45660 KB Output is correct
14 Correct 11 ms 45660 KB Output is correct
15 Correct 11 ms 45404 KB Output is correct
16 Correct 11 ms 45656 KB Output is correct
17 Correct 11 ms 45404 KB Output is correct
18 Correct 12 ms 45660 KB Output is correct
19 Correct 12 ms 45672 KB Output is correct
20 Correct 12 ms 45656 KB Output is correct
21 Correct 113 ms 47444 KB Output is correct
22 Correct 112 ms 47892 KB Output is correct
23 Correct 105 ms 47444 KB Output is correct
24 Correct 96 ms 47556 KB Output is correct
25 Correct 115 ms 48008 KB Output is correct
26 Correct 101 ms 47760 KB Output is correct
27 Correct 53 ms 47044 KB Output is correct
28 Correct 50 ms 47080 KB Output is correct
29 Correct 95 ms 47388 KB Output is correct
30 Correct 110 ms 47768 KB Output is correct
31 Correct 99 ms 47444 KB Output is correct
32 Correct 104 ms 47444 KB Output is correct
33 Correct 80 ms 47952 KB Output is correct
34 Correct 119 ms 48168 KB Output is correct
35 Correct 93 ms 48712 KB Output is correct
36 Correct 97 ms 48724 KB Output is correct
37 Correct 91 ms 47444 KB Output is correct
38 Correct 80 ms 47348 KB Output is correct
39 Correct 45 ms 46792 KB Output is correct
40 Correct 44 ms 46760 KB Output is correct
41 Correct 89 ms 47560 KB Output is correct
42 Correct 89 ms 47440 KB Output is correct
43 Correct 105 ms 47628 KB Output is correct
44 Correct 117 ms 47444 KB Output is correct
45 Correct 90 ms 47440 KB Output is correct
46 Correct 103 ms 47440 KB Output is correct
47 Correct 51 ms 47036 KB Output is correct
48 Correct 83 ms 47880 KB Output is correct
49 Correct 96 ms 46988 KB Output is correct
50 Correct 103 ms 47132 KB Output is correct
51 Correct 114 ms 47628 KB Output is correct
52 Correct 119 ms 47444 KB Output is correct
53 Correct 93 ms 48236 KB Output is correct
54 Correct 94 ms 48692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 48212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 45656 KB Output is correct
2 Correct 12 ms 45660 KB Output is correct
3 Correct 11 ms 45608 KB Output is correct
4 Correct 12 ms 45660 KB Output is correct
5 Correct 11 ms 45584 KB Output is correct
6 Correct 10 ms 45660 KB Output is correct
7 Correct 12 ms 45672 KB Output is correct
8 Correct 13 ms 45660 KB Output is correct
9 Correct 12 ms 45660 KB Output is correct
10 Correct 12 ms 45660 KB Output is correct
11 Correct 12 ms 45572 KB Output is correct
12 Correct 12 ms 45660 KB Output is correct
13 Correct 12 ms 45660 KB Output is correct
14 Correct 11 ms 45660 KB Output is correct
15 Correct 11 ms 45404 KB Output is correct
16 Correct 11 ms 45656 KB Output is correct
17 Correct 11 ms 45404 KB Output is correct
18 Correct 12 ms 45660 KB Output is correct
19 Correct 12 ms 45672 KB Output is correct
20 Correct 12 ms 45656 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 12 ms 45656 KB Output is correct
2 Correct 12 ms 45660 KB Output is correct
3 Correct 11 ms 45608 KB Output is correct
4 Correct 12 ms 45660 KB Output is correct
5 Correct 11 ms 45584 KB Output is correct
6 Correct 10 ms 45660 KB Output is correct
7 Correct 12 ms 45672 KB Output is correct
8 Correct 13 ms 45660 KB Output is correct
9 Correct 12 ms 45660 KB Output is correct
10 Correct 12 ms 45660 KB Output is correct
11 Correct 12 ms 45572 KB Output is correct
12 Correct 12 ms 45660 KB Output is correct
13 Correct 12 ms 45660 KB Output is correct
14 Correct 11 ms 45660 KB Output is correct
15 Correct 11 ms 45404 KB Output is correct
16 Correct 11 ms 45656 KB Output is correct
17 Correct 11 ms 45404 KB Output is correct
18 Correct 12 ms 45660 KB Output is correct
19 Correct 12 ms 45672 KB Output is correct
20 Correct 12 ms 45656 KB Output is correct
21 Incorrect 12 ms 45660 KB Output isn't correct
22 Halted 0 ms 0 KB -