Submission #976885

# Submission time Handle Problem Language Result Execution time Memory
976885 2024-05-07T08:30:06 Z zwezdinv Food Court (JOI21_foodcourt) C++17
24 / 100
436 ms 74320 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);
    }
}

const int B = 500;

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

ll to_f[N];
bool to_ans[N];
vector<int> ev[N];
vector<pair<int, ll>> upd[N];
int ans[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);
            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].push_back(i);
            to_f[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 : ev[i]) {
            int k = ST2::find(id, to_f[id]);
            if (k == -1) ans[id] = 0;
            else 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 40 ms 65616 KB Output is correct
2 Correct 24 ms 65628 KB Output is correct
3 Correct 22 ms 65804 KB Output is correct
4 Correct 25 ms 65620 KB Output is correct
5 Correct 23 ms 65628 KB Output is correct
6 Correct 22 ms 65628 KB Output is correct
7 Correct 24 ms 65628 KB Output is correct
8 Correct 23 ms 65628 KB Output is correct
9 Correct 24 ms 65624 KB Output is correct
10 Correct 23 ms 65628 KB Output is correct
11 Correct 24 ms 65808 KB Output is correct
12 Correct 24 ms 65624 KB Output is correct
13 Correct 28 ms 65628 KB Output is correct
14 Correct 24 ms 65628 KB Output is correct
15 Correct 23 ms 65628 KB Output is correct
16 Correct 24 ms 65628 KB Output is correct
17 Correct 24 ms 65628 KB Output is correct
18 Correct 24 ms 65628 KB Output is correct
19 Correct 24 ms 65628 KB Output is correct
20 Correct 23 ms 65628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 65616 KB Output is correct
2 Correct 24 ms 65628 KB Output is correct
3 Correct 22 ms 65804 KB Output is correct
4 Correct 25 ms 65620 KB Output is correct
5 Correct 23 ms 65628 KB Output is correct
6 Correct 22 ms 65628 KB Output is correct
7 Correct 24 ms 65628 KB Output is correct
8 Correct 23 ms 65628 KB Output is correct
9 Correct 24 ms 65624 KB Output is correct
10 Correct 23 ms 65628 KB Output is correct
11 Correct 24 ms 65808 KB Output is correct
12 Correct 24 ms 65624 KB Output is correct
13 Correct 28 ms 65628 KB Output is correct
14 Correct 24 ms 65628 KB Output is correct
15 Correct 23 ms 65628 KB Output is correct
16 Correct 24 ms 65628 KB Output is correct
17 Correct 24 ms 65628 KB Output is correct
18 Correct 24 ms 65628 KB Output is correct
19 Correct 24 ms 65628 KB Output is correct
20 Correct 23 ms 65628 KB Output is correct
21 Incorrect 23 ms 65752 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 110 ms 69712 KB Output is correct
2 Correct 142 ms 70136 KB Output is correct
3 Correct 116 ms 67648 KB Output is correct
4 Correct 114 ms 69788 KB Output is correct
5 Correct 116 ms 68296 KB Output is correct
6 Correct 116 ms 69972 KB Output is correct
7 Correct 63 ms 68800 KB Output is correct
8 Correct 62 ms 68832 KB Output is correct
9 Correct 112 ms 69712 KB Output is correct
10 Correct 119 ms 67612 KB Output is correct
11 Correct 120 ms 69576 KB Output is correct
12 Correct 121 ms 69552 KB Output is correct
13 Correct 94 ms 69900 KB Output is correct
14 Correct 109 ms 70336 KB Output is correct
15 Correct 111 ms 70992 KB Output is correct
16 Correct 120 ms 70996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 436 ms 74320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 65616 KB Output is correct
2 Correct 24 ms 65628 KB Output is correct
3 Correct 22 ms 65804 KB Output is correct
4 Correct 25 ms 65620 KB Output is correct
5 Correct 23 ms 65628 KB Output is correct
6 Correct 22 ms 65628 KB Output is correct
7 Correct 24 ms 65628 KB Output is correct
8 Correct 23 ms 65628 KB Output is correct
9 Correct 24 ms 65624 KB Output is correct
10 Correct 23 ms 65628 KB Output is correct
11 Correct 24 ms 65808 KB Output is correct
12 Correct 24 ms 65624 KB Output is correct
13 Correct 28 ms 65628 KB Output is correct
14 Correct 24 ms 65628 KB Output is correct
15 Correct 23 ms 65628 KB Output is correct
16 Correct 24 ms 65628 KB Output is correct
17 Correct 24 ms 65628 KB Output is correct
18 Correct 24 ms 65628 KB Output is correct
19 Correct 24 ms 65628 KB Output is correct
20 Correct 23 ms 65628 KB Output is correct
21 Correct 110 ms 69712 KB Output is correct
22 Correct 142 ms 70136 KB Output is correct
23 Correct 116 ms 67648 KB Output is correct
24 Correct 114 ms 69788 KB Output is correct
25 Correct 116 ms 68296 KB Output is correct
26 Correct 116 ms 69972 KB Output is correct
27 Correct 63 ms 68800 KB Output is correct
28 Correct 62 ms 68832 KB Output is correct
29 Correct 112 ms 69712 KB Output is correct
30 Correct 119 ms 67612 KB Output is correct
31 Correct 120 ms 69576 KB Output is correct
32 Correct 121 ms 69552 KB Output is correct
33 Correct 94 ms 69900 KB Output is correct
34 Correct 109 ms 70336 KB Output is correct
35 Correct 111 ms 70992 KB Output is correct
36 Correct 120 ms 70996 KB Output is correct
37 Correct 106 ms 69704 KB Output is correct
38 Correct 90 ms 67664 KB Output is correct
39 Correct 51 ms 68808 KB Output is correct
40 Correct 57 ms 68920 KB Output is correct
41 Correct 108 ms 67688 KB Output is correct
42 Correct 103 ms 69716 KB Output is correct
43 Correct 117 ms 69692 KB Output is correct
44 Correct 129 ms 67712 KB Output is correct
45 Correct 102 ms 67664 KB Output is correct
46 Correct 113 ms 69756 KB Output is correct
47 Correct 64 ms 69304 KB Output is correct
48 Correct 101 ms 69604 KB Output is correct
49 Correct 91 ms 66996 KB Output is correct
50 Correct 112 ms 69456 KB Output is correct
51 Correct 134 ms 69716 KB Output is correct
52 Correct 136 ms 69712 KB Output is correct
53 Correct 90 ms 68184 KB Output is correct
54 Correct 114 ms 70992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 117 ms 70096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 65616 KB Output is correct
2 Correct 24 ms 65628 KB Output is correct
3 Correct 22 ms 65804 KB Output is correct
4 Correct 25 ms 65620 KB Output is correct
5 Correct 23 ms 65628 KB Output is correct
6 Correct 22 ms 65628 KB Output is correct
7 Correct 24 ms 65628 KB Output is correct
8 Correct 23 ms 65628 KB Output is correct
9 Correct 24 ms 65624 KB Output is correct
10 Correct 23 ms 65628 KB Output is correct
11 Correct 24 ms 65808 KB Output is correct
12 Correct 24 ms 65624 KB Output is correct
13 Correct 28 ms 65628 KB Output is correct
14 Correct 24 ms 65628 KB Output is correct
15 Correct 23 ms 65628 KB Output is correct
16 Correct 24 ms 65628 KB Output is correct
17 Correct 24 ms 65628 KB Output is correct
18 Correct 24 ms 65628 KB Output is correct
19 Correct 24 ms 65628 KB Output is correct
20 Correct 23 ms 65628 KB Output is correct
21 Incorrect 23 ms 65752 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 65616 KB Output is correct
2 Correct 24 ms 65628 KB Output is correct
3 Correct 22 ms 65804 KB Output is correct
4 Correct 25 ms 65620 KB Output is correct
5 Correct 23 ms 65628 KB Output is correct
6 Correct 22 ms 65628 KB Output is correct
7 Correct 24 ms 65628 KB Output is correct
8 Correct 23 ms 65628 KB Output is correct
9 Correct 24 ms 65624 KB Output is correct
10 Correct 23 ms 65628 KB Output is correct
11 Correct 24 ms 65808 KB Output is correct
12 Correct 24 ms 65624 KB Output is correct
13 Correct 28 ms 65628 KB Output is correct
14 Correct 24 ms 65628 KB Output is correct
15 Correct 23 ms 65628 KB Output is correct
16 Correct 24 ms 65628 KB Output is correct
17 Correct 24 ms 65628 KB Output is correct
18 Correct 24 ms 65628 KB Output is correct
19 Correct 24 ms 65628 KB Output is correct
20 Correct 23 ms 65628 KB Output is correct
21 Incorrect 23 ms 65752 KB Output isn't correct
22 Halted 0 ms 0 KB -