Submission #1007342

# Submission time Handle Problem Language Result Execution time Memory
1007342 2024-06-24T16:05:16 Z LOLOLO Food Court (JOI21_foodcourt) C++17
24 / 100
121 ms 89288 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (ll)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())

const int N = 5e5 + 20;

struct seg{
    vector <ll> sum, mi;
    seg(int n) {
        sum.assign(n * 4 + 100, 0);
        mi.assign(n * 4 + 100, 0);
    }

    void upd(int i, int l, int r, int p, ll v) {
        if (l > p || r < p)
            return;

        if (l == r) {
            sum[i] += v;
            mi[i] = min((ll)0, sum[i]);
            return; 
        }

        int m = (l + r) / 2;
        upd(i * 2, l, m, p, v);
        upd(i * 2 + 1, m + 1, r, p, v);
        sum[i] = sum[i * 2] + sum[i * 2 + 1];
        mi[i] = min(mi[i * 2], sum[i * 2] + mi[i * 2 + 1]);
    }

    pair <ll, ll> get(int i, int l, int r, int u) {
        if (l > u)
            return {0, 0};

        if (r <= u)
            return {sum[i], mi[i]};

        int m = (l + r) / 2;
        pair <ll, ll> A = get(i * 2, l, m, u), B = get(i * 2 + 1, m + 1, r, u);
        return {A.f + B.f, min(A.s, B.s + A.f)};
    }
};

struct fen{
    vector <ll> f;
    int N;
    fen(int n) {
        N = n;
        f.assign(n + 1, 0);
    }

    void upd(int i, int x) {
        for (; i <= N; i += i & (-i))
            f[i] += x;
    }

    ll get(int i) {
        ll s = 0;
        for (; i; i -= i & (-i))
            s += f[i];

        return s;
    }
};

struct ST{
    vector <pair <ll, ll>> st;
    vector <ll> laz;

    void build(int i, int l, int r) {
        if (l == r) {
            st[i] = {0, l};
            return;
        }

        int m = (l + r) / 2;
        build(i * 2, l, m);
        build(i * 2 + 1, m + 1, r);
        st[i] = min(st[i * 2], st[i * 2 + 1]);
    }

    ST(int n) {
        st.assign(n * 4 + 10, {0, 0});
        laz.assign(n * 4 + 10, 0);
        build(1, 1, n);
    }

    void push(int i) {
        ll t = laz[i];
        laz[i * 2] += t;
        laz[i * 2 + 1] += t;
        st[i * 2].f += t;
        st[i * 2 + 1].f += t;
        laz[i] = 0;
    }

    void upd(int i, int l, int r, int u, int v, ll c) {
        if (l > v || r < u)
            return;

        if (l >= u && r <= v) {
            laz[i] += c;
            st[i].f += c;
            return;
        }

        push(i);
        int m = (l + r) / 2;
        upd(i * 2, l, m, u, v, c);
        upd(i * 2 + 1, m + 1, r, u, v, c);
        st[i] = min(st[i * 2], st[i * 2 + 1]);
    }

    pair <ll, ll> get() {
        return st[1];
    }
};

ll ans[N];
bool is[N];

vector < pair <ll, ll>> event[N], add[N], ask[N], save[N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    vector < vector <ll>> need;
    int n, m, q;
    cin >> n >> m >> q;

    fen bit(q);
    seg seg(q);
    ST st(n);

    for (int i = 1; i <= q; i++) {
        int t;
        cin >> t;
        if (t == 1) {
            int l, r, c, k;
            cin >> l >> r >> c >> k;
            need.pb({l, r, c, k});
            add[l].pb({i, k});
            add[r + 1].pb({i, -k});
            event[l].pb({i, k});
            event[r + 1].pb({i, -k});
        }

        if (t == 2) {
            int l, r, k;
            cin >> l >> r >> k;
            event[l].pb({i, -k});
            event[r + 1].pb({i, k});   
        }

        if (t == 3) {
            int a, b;
            cin >> a >> b;
            ask[a].pb({i, b});
            is[i] = 1;
        }
    }

    for (int i = 1; i <= n; i++) {
        for (auto x : event[i]) {
            seg.upd(1, 1, q, x.f, x.s);
        }

        for (auto x : add[i]) {
            bit.upd(x.f, x.s);
        }

        for (auto x : ask[i]) {
            pair <ll, ll> tt = seg.get(1, 1, q, x.f);
            ll num = tt.f - tt.s;
            if (num >= x.s) {
                save[i].pb({bit.get(x.f) - (num - x.s), x.f});
            }
        }

        sort(all(save[i]), greater <pair <ll, ll>> ());
        if (sz(save[i])) {
            st.upd(1, 1, n, i, i, save[i].back().f);
        } else {
            st.upd(1, 1, n, i, i, 1e16);
        }
    }

    for (auto x : need) {
        st.upd(1, 1, n, x[0], x[1], -x[3]);
        while (1) {
            pair <ll, ll> tt = st.get();
            if (tt.f <= 0) {
                int i = tt.s;
                ans[save[i].back().s] = x[2];
                ll pr = save[i].back().f;
                save[i].pop_back();
                if (sz(save[i])) {
                    st.upd(1, 1, n, i, i, save[i].back().f - pr);
                } else {
                    st.upd(1, 1, n, i, i, 1e16 - pr);
                }
            } else {
                break;
            }
        }
    }

    for (int i = 1; i <= q; i++) {
        if (is[i]) {
            cout << ans[i] << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 48220 KB Output is correct
2 Correct 18 ms 48220 KB Output is correct
3 Correct 17 ms 48072 KB Output is correct
4 Correct 18 ms 48220 KB Output is correct
5 Correct 17 ms 47964 KB Output is correct
6 Correct 17 ms 47960 KB Output is correct
7 Correct 18 ms 48220 KB Output is correct
8 Correct 19 ms 48216 KB Output is correct
9 Correct 18 ms 48220 KB Output is correct
10 Correct 18 ms 48184 KB Output is correct
11 Correct 18 ms 48220 KB Output is correct
12 Correct 22 ms 48220 KB Output is correct
13 Correct 17 ms 48220 KB Output is correct
14 Correct 18 ms 48216 KB Output is correct
15 Correct 19 ms 48216 KB Output is correct
16 Correct 19 ms 48220 KB Output is correct
17 Correct 18 ms 48092 KB Output is correct
18 Correct 18 ms 48216 KB Output is correct
19 Correct 18 ms 48336 KB Output is correct
20 Correct 19 ms 48496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 48220 KB Output is correct
2 Correct 18 ms 48220 KB Output is correct
3 Correct 17 ms 48072 KB Output is correct
4 Correct 18 ms 48220 KB Output is correct
5 Correct 17 ms 47964 KB Output is correct
6 Correct 17 ms 47960 KB Output is correct
7 Correct 18 ms 48220 KB Output is correct
8 Correct 19 ms 48216 KB Output is correct
9 Correct 18 ms 48220 KB Output is correct
10 Correct 18 ms 48184 KB Output is correct
11 Correct 18 ms 48220 KB Output is correct
12 Correct 22 ms 48220 KB Output is correct
13 Correct 17 ms 48220 KB Output is correct
14 Correct 18 ms 48216 KB Output is correct
15 Correct 19 ms 48216 KB Output is correct
16 Correct 19 ms 48220 KB Output is correct
17 Correct 18 ms 48092 KB Output is correct
18 Correct 18 ms 48216 KB Output is correct
19 Correct 18 ms 48336 KB Output is correct
20 Correct 19 ms 48496 KB Output is correct
21 Incorrect 18 ms 48108 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 93 ms 65164 KB Output is correct
2 Correct 101 ms 66824 KB Output is correct
3 Correct 87 ms 65292 KB Output is correct
4 Correct 85 ms 65312 KB Output is correct
5 Correct 116 ms 66828 KB Output is correct
6 Correct 99 ms 66748 KB Output is correct
7 Correct 38 ms 57108 KB Output is correct
8 Correct 40 ms 57324 KB Output is correct
9 Correct 86 ms 66020 KB Output is correct
10 Correct 88 ms 66060 KB Output is correct
11 Correct 96 ms 65800 KB Output is correct
12 Correct 87 ms 65688 KB Output is correct
13 Correct 81 ms 64008 KB Output is correct
14 Correct 98 ms 67336 KB Output is correct
15 Correct 103 ms 67588 KB Output is correct
16 Correct 107 ms 69896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 96 ms 89288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 48220 KB Output is correct
2 Correct 18 ms 48220 KB Output is correct
3 Correct 17 ms 48072 KB Output is correct
4 Correct 18 ms 48220 KB Output is correct
5 Correct 17 ms 47964 KB Output is correct
6 Correct 17 ms 47960 KB Output is correct
7 Correct 18 ms 48220 KB Output is correct
8 Correct 19 ms 48216 KB Output is correct
9 Correct 18 ms 48220 KB Output is correct
10 Correct 18 ms 48184 KB Output is correct
11 Correct 18 ms 48220 KB Output is correct
12 Correct 22 ms 48220 KB Output is correct
13 Correct 17 ms 48220 KB Output is correct
14 Correct 18 ms 48216 KB Output is correct
15 Correct 19 ms 48216 KB Output is correct
16 Correct 19 ms 48220 KB Output is correct
17 Correct 18 ms 48092 KB Output is correct
18 Correct 18 ms 48216 KB Output is correct
19 Correct 18 ms 48336 KB Output is correct
20 Correct 19 ms 48496 KB Output is correct
21 Correct 93 ms 65164 KB Output is correct
22 Correct 101 ms 66824 KB Output is correct
23 Correct 87 ms 65292 KB Output is correct
24 Correct 85 ms 65312 KB Output is correct
25 Correct 116 ms 66828 KB Output is correct
26 Correct 99 ms 66748 KB Output is correct
27 Correct 38 ms 57108 KB Output is correct
28 Correct 40 ms 57324 KB Output is correct
29 Correct 86 ms 66020 KB Output is correct
30 Correct 88 ms 66060 KB Output is correct
31 Correct 96 ms 65800 KB Output is correct
32 Correct 87 ms 65688 KB Output is correct
33 Correct 81 ms 64008 KB Output is correct
34 Correct 98 ms 67336 KB Output is correct
35 Correct 103 ms 67588 KB Output is correct
36 Correct 107 ms 69896 KB Output is correct
37 Correct 93 ms 64268 KB Output is correct
38 Correct 104 ms 64136 KB Output is correct
39 Correct 36 ms 56428 KB Output is correct
40 Correct 40 ms 57280 KB Output is correct
41 Correct 107 ms 66316 KB Output is correct
42 Correct 121 ms 66672 KB Output is correct
43 Correct 115 ms 66356 KB Output is correct
44 Correct 100 ms 66380 KB Output is correct
45 Correct 96 ms 66316 KB Output is correct
46 Correct 112 ms 66492 KB Output is correct
47 Correct 64 ms 64628 KB Output is correct
48 Correct 83 ms 65800 KB Output is correct
49 Correct 81 ms 60844 KB Output is correct
50 Correct 87 ms 64520 KB Output is correct
51 Correct 99 ms 66572 KB Output is correct
52 Correct 97 ms 66552 KB Output is correct
53 Correct 85 ms 65540 KB Output is correct
54 Correct 106 ms 70148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 60484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 48220 KB Output is correct
2 Correct 18 ms 48220 KB Output is correct
3 Correct 17 ms 48072 KB Output is correct
4 Correct 18 ms 48220 KB Output is correct
5 Correct 17 ms 47964 KB Output is correct
6 Correct 17 ms 47960 KB Output is correct
7 Correct 18 ms 48220 KB Output is correct
8 Correct 19 ms 48216 KB Output is correct
9 Correct 18 ms 48220 KB Output is correct
10 Correct 18 ms 48184 KB Output is correct
11 Correct 18 ms 48220 KB Output is correct
12 Correct 22 ms 48220 KB Output is correct
13 Correct 17 ms 48220 KB Output is correct
14 Correct 18 ms 48216 KB Output is correct
15 Correct 19 ms 48216 KB Output is correct
16 Correct 19 ms 48220 KB Output is correct
17 Correct 18 ms 48092 KB Output is correct
18 Correct 18 ms 48216 KB Output is correct
19 Correct 18 ms 48336 KB Output is correct
20 Correct 19 ms 48496 KB Output is correct
21 Incorrect 18 ms 48108 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 48220 KB Output is correct
2 Correct 18 ms 48220 KB Output is correct
3 Correct 17 ms 48072 KB Output is correct
4 Correct 18 ms 48220 KB Output is correct
5 Correct 17 ms 47964 KB Output is correct
6 Correct 17 ms 47960 KB Output is correct
7 Correct 18 ms 48220 KB Output is correct
8 Correct 19 ms 48216 KB Output is correct
9 Correct 18 ms 48220 KB Output is correct
10 Correct 18 ms 48184 KB Output is correct
11 Correct 18 ms 48220 KB Output is correct
12 Correct 22 ms 48220 KB Output is correct
13 Correct 17 ms 48220 KB Output is correct
14 Correct 18 ms 48216 KB Output is correct
15 Correct 19 ms 48216 KB Output is correct
16 Correct 19 ms 48220 KB Output is correct
17 Correct 18 ms 48092 KB Output is correct
18 Correct 18 ms 48216 KB Output is correct
19 Correct 18 ms 48336 KB Output is correct
20 Correct 19 ms 48496 KB Output is correct
21 Incorrect 18 ms 48108 KB Output isn't correct
22 Halted 0 ms 0 KB -