Submission #933764

# Submission time Handle Problem Language Result Execution time Memory
933764 2024-02-26T09:40:25 Z Pannda Food Court (JOI21_foodcourt) C++17
24 / 100
87 ms 35136 KB
#include <bits/stdc++.h>
using namespace std;

struct SegmentTree {
    int n;
    vector<long long> a, b;

    SegmentTree(int n) : n(n), a(4 * n, 0), b(4 * n, 0) {}

    void apply(int idx, long long x, long long y) {
        b[idx] = max(b[idx] + x, y);
        a[idx] = a[idx] + x;
    }

    void down(int idx) {
        apply(2 * idx + 1, a[idx], b[idx]);
        apply(2 * idx + 2, a[idx], b[idx]);
        a[idx] = b[idx] = 0;
    }

    void add(int ql, int qr, long long x, long long y) {
        auto dfs = [&](auto self, int idx, int l, int r) {
            if (r <= ql || qr <= l) return;
            if (ql <= l && r <= qr) return apply(idx, x, y);
            down(idx);
            int m = (l + r) >> 1;
            self(self, 2 * idx + 1, l, m);
            self(self, 2 * idx + 2, m, r);
        };
        dfs(dfs, 0, 0, n);
    }

    long long get(int pos) {
        int idx = 0, l = 0, r = n;
        while (l + 1 < r) {
            down(idx);
            int m = (l + r) >> 1;
            if (pos < m) {
                idx = 2 * idx + 1;
                r = m;
            } else {
                idx = 2 * idx + 2;
                l = m;
            }
        }
        return max(a[idx], b[idx]);
    }
};

struct Fenwick {
    int n;
    vector<long long> bit;

    Fenwick(int n) : n(n), bit(n + 1, 0) {}

    void add(int i, long long delta) {
        for (i++; i <= n; i += i & -i) {
            bit[i] += delta;
        }
    }

    void add(int ql, int qr, long long delta) {
        add(ql, +delta);
        add(qr, -delta);
    }

    long long get(int i) {
        long long res = 0;
        for (i++; i > 0; i -= i & -i) {
            res += bit[i];
        }
        return res;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, q;
    cin >> n >> m >> q;

    vector<int> type(q), l(q), r(q), c(q), k(q), a(q), b(q);
    for (int i = 0; i < q; i++) {
        cin >> type[i];
        if (type[i] == 1) {
            cin >> l[i] >> r[i] >> c[i] >> k[i];
            l[i]--;
        }
        if (type[i] == 2) {
            cin >> l[i] >> r[i] >> k[i];
            l[i]--;
        }
        if (type[i] == 3) {
            cin >> a[i] >> b[i];
            a[i]--;
            b[i]--;
        }
    }

    SegmentTree seg(n);
    Fenwick fen(n);
    vector<vector<int>> inbox(q + 1);

    for (int i = 0; i < q; i++) {
        if (type[i] == 1) {
            seg.add(l[i], r[i], k[i], 0);
            fen.add(l[i], r[i], k[i]);
        }
        if (type[i] == 2) {
            seg.add(l[i], r[i], -k[i], 0);
        }
        if (type[i] == 3) {
            long long seg_get = seg.get(a[i]);
            long long fen_get = fen.get(a[i]);
            b[i] = fen_get - seg_get + b[i];
            l[i] = 0, r[i] = q - 1;
            inbox[(l[i] + r[i]) >> 1].push_back(i);
        }
    }

    const int LOG = 18;
    for (int ite = 0; ite < LOG; ite++) {
        Fenwick fen(n);
        vector<vector<int>> new_inbox(q + 1);
        for (int m = 0; m < q; m++) {
            if (type[m] == 1) {
                fen.add(l[m], r[m], k[m]);
            }
            for (int i : inbox[m]) {
                if (b[i] < fen.get(a[i])) {
                    r[i] = m;
                } else {
                    l[i] = m + 1;
                }
                new_inbox[(l[i] + r[i]) >> 1].push_back(i);
            }
        }
        inbox = new_inbox;
    }

    for (int i = 0; i < q; i++) {
        if (type[i] == 3) {
            if (l[i] > i) {
                cout << 0 << '\n';
            } else {
                cout << c[l[i]] << '\n';
            }
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 3 ms 1120 KB Output is correct
3 Correct 2 ms 744 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 720 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 832 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 3 ms 1120 KB Output is correct
3 Correct 2 ms 744 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 720 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 832 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Incorrect 1 ms 604 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 76 ms 13652 KB Output is correct
2 Correct 83 ms 13252 KB Output is correct
3 Correct 77 ms 13920 KB Output is correct
4 Correct 81 ms 13960 KB Output is correct
5 Correct 85 ms 13476 KB Output is correct
6 Correct 83 ms 13416 KB Output is correct
7 Correct 38 ms 8092 KB Output is correct
8 Correct 39 ms 8120 KB Output is correct
9 Correct 73 ms 13152 KB Output is correct
10 Correct 78 ms 13144 KB Output is correct
11 Correct 74 ms 13148 KB Output is correct
12 Correct 75 ms 13208 KB Output is correct
13 Correct 78 ms 11412 KB Output is correct
14 Correct 84 ms 13920 KB Output is correct
15 Correct 85 ms 11380 KB Output is correct
16 Correct 87 ms 12984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 35136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 3 ms 1120 KB Output is correct
3 Correct 2 ms 744 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 720 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 832 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 76 ms 13652 KB Output is correct
22 Correct 83 ms 13252 KB Output is correct
23 Correct 77 ms 13920 KB Output is correct
24 Correct 81 ms 13960 KB Output is correct
25 Correct 85 ms 13476 KB Output is correct
26 Correct 83 ms 13416 KB Output is correct
27 Correct 38 ms 8092 KB Output is correct
28 Correct 39 ms 8120 KB Output is correct
29 Correct 73 ms 13152 KB Output is correct
30 Correct 78 ms 13144 KB Output is correct
31 Correct 74 ms 13148 KB Output is correct
32 Correct 75 ms 13208 KB Output is correct
33 Correct 78 ms 11412 KB Output is correct
34 Correct 84 ms 13920 KB Output is correct
35 Correct 85 ms 11380 KB Output is correct
36 Correct 87 ms 12984 KB Output is correct
37 Correct 81 ms 12740 KB Output is correct
38 Correct 73 ms 11276 KB Output is correct
39 Correct 31 ms 6524 KB Output is correct
40 Correct 39 ms 7372 KB Output is correct
41 Correct 80 ms 13152 KB Output is correct
42 Correct 82 ms 13384 KB Output is correct
43 Correct 83 ms 13292 KB Output is correct
44 Correct 81 ms 13356 KB Output is correct
45 Correct 85 ms 13412 KB Output is correct
46 Correct 85 ms 13408 KB Output is correct
47 Correct 59 ms 13852 KB Output is correct
48 Correct 80 ms 13968 KB Output is correct
49 Correct 58 ms 9240 KB Output is correct
50 Correct 71 ms 12068 KB Output is correct
51 Correct 83 ms 13292 KB Output is correct
52 Correct 87 ms 13156 KB Output is correct
53 Correct 68 ms 10740 KB Output is correct
54 Correct 87 ms 13000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 9716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 3 ms 1120 KB Output is correct
3 Correct 2 ms 744 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 720 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 832 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Incorrect 1 ms 604 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 3 ms 1120 KB Output is correct
3 Correct 2 ms 744 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 720 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 832 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Incorrect 1 ms 604 KB Output isn't correct
22 Halted 0 ms 0 KB -