Submission #998641

# Submission time Handle Problem Language Result Execution time Memory
998641 2024-06-14T11:59:12 Z vladilius Food Court (JOI21_foodcourt) C++17
24 / 100
1000 ms 38856 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
#define pb push_back
#define ff first
#define ss second
#define ins insert

struct ST{
    struct node{
        ll sum, max_suf;
    };
    vector<node> t;
    node null;
    int n;
    ST(int ns){
        n = ns;
        t.resize(4 * n);
        null = {0, 0};
    }
    node merge(node x, node y){
        return {x.sum + y.sum, max(y.max_suf, x.max_suf + y.sum)};
    }
    void upd(int v, int tl, int tr, int& p, int& k){
        if (tl == tr){
            t[v] = {k, k};
            return;
        }
        int tm = (tl + tr) / 2, vv = 2 * v;
        if (p <= tm){
            upd(vv, tl, tm, p, k);
        }
        else {
            upd(vv + 1, tm + 1, tr, p, k);
        }
        t[v] = merge(t[vv], t[vv + 1]);
    }
    void upd(int p, int k){
        upd(1, 1, n, p, k);
    }
    node get(int v, int tl, int tr, int& l, int& r){
        if (l > tr || r < tl) return null;
        if (l <= tl && tr <= r) return t[v];
        int tm = (tl + tr) / 2, vv = 2 * v;
        return merge(get(vv, tl, tm, l, r), get(vv + 1, tm + 1, tr, l, r));
    }
    ll get(int l, int r){
        return get(1, 1, n, l, r).max_suf;
    }
};

struct ST1{
    vector<ll> t;
    int n;
    ST1(int ns){
        n = ns;
        t.resize(4 * n);
    }
    void upd(int v, int tl, int tr, int& p, int& k){
        if (tl == tr){
            t[v] = k;
            return;
        }
        int tm = (tl + tr) / 2, vv = 2 * v;
        if (p <= tm){
            upd(vv, tl, tm, p, k);
        }
        else {
            upd(vv + 1, tm + 1, tr, p, k);
        }
        t[v] = t[vv] + t[vv + 1];
    }
    void upd(int p, int k){
        upd(1, 1, n, p, k);
    }
    ll get(int v, int tl, int tr, int& l, int& r){
        if (l > tr || r < tl) return 0;
        if (l <= tl && tr <= r) return t[v];
        int tm = (tl + tr) / 2, vv = 2 * v;
        return get(vv, tl, tm, l, r) + get(vv + 1, tm + 1, tr, l, r);
    }
    ll get(int l, int r){
        return get(1, 1, n, l, r);
    }
    int get_p(int r, ll k){
        int bl = 1, br = r;
        while (bl + 1 < br){
            int m = (bl + br) / 2;
            if (get(1, m) >= k){
                br = m;
            }
            else {
                bl = m + 1;
            }
        }
        if (get(1, bl) >= k) br = bl;
        return br;
    }
};

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, m, q; cin>>n>>m>>q;
    vector<pii> st[n + 2];
    vector<pil> qs[n + 1];
    vector<int> col(q + 1);
    for (int tt = 1; tt <= q; tt++){
        int type; cin>>type;
        if (type == 1){
            int l, r, c, k; cin>>l>>r>>c>>k;
            st[l].pb({tt, k});
            st[r + 1].pb({tt, 0});
            col[tt] = c;
        }
        else if (type == 2){
            int l, r, k; cin>>l>>r>>k;
            st[l].pb({tt, -k});
            st[r + 1].pb({tt, 0});
        }
        else {
            int a, b; cin>>a>>b;
            qs[a].pb({tt, b});
        }
    }
    ST T(q);
    ST1 Ts(q);
    vector<int> out(q + 1, -1), a(q + 1);
    for (int i = 1; i <= n; i++){
        for (auto [j, k]: st[i]){
            T.upd(j, k);
            a[j] = k;
            if (k >= 0) Ts.upd(j, k);
        }
        for (auto [j, b]: qs[i]){
            ll cur = T.get(1, j);
            ll sum = 0, maxi = 0;
            for (int t = j; t > 0; t--){
                sum += a[t];
                maxi = max(maxi, sum);
            }
            if (maxi != cur) return 1;
            if (b > cur){
                out[j] = 0;
                continue;
            }
            b = Ts.get(1, j) - cur + b;
            out[j] = col[Ts.get_p(j, b)];
        }
    }
    for (int i = 1; i <= q; i++){
        if (out[i] != -1){
            cout<<out[i]<<"\n";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 1 ms 568 KB Output is correct
4 Correct 2 ms 824 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 824 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 828 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 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 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 1 ms 568 KB Output is correct
4 Correct 2 ms 824 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 824 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 828 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 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 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Incorrect 3 ms 604 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 532 ms 12636 KB Output is correct
2 Correct 433 ms 12664 KB Output is correct
3 Correct 521 ms 12636 KB Output is correct
4 Correct 532 ms 12680 KB Output is correct
5 Correct 403 ms 12688 KB Output is correct
6 Correct 407 ms 12492 KB Output is correct
7 Correct 434 ms 7812 KB Output is correct
8 Correct 437 ms 8184 KB Output is correct
9 Correct 427 ms 12880 KB Output is correct
10 Correct 414 ms 12664 KB Output is correct
11 Correct 405 ms 12636 KB Output is correct
12 Correct 406 ms 12668 KB Output is correct
13 Correct 426 ms 10588 KB Output is correct
14 Correct 515 ms 12884 KB Output is correct
15 Correct 261 ms 11384 KB Output is correct
16 Correct 268 ms 12632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1034 ms 38856 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 1 ms 568 KB Output is correct
4 Correct 2 ms 824 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 824 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 828 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 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 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 532 ms 12636 KB Output is correct
22 Correct 433 ms 12664 KB Output is correct
23 Correct 521 ms 12636 KB Output is correct
24 Correct 532 ms 12680 KB Output is correct
25 Correct 403 ms 12688 KB Output is correct
26 Correct 407 ms 12492 KB Output is correct
27 Correct 434 ms 7812 KB Output is correct
28 Correct 437 ms 8184 KB Output is correct
29 Correct 427 ms 12880 KB Output is correct
30 Correct 414 ms 12664 KB Output is correct
31 Correct 405 ms 12636 KB Output is correct
32 Correct 406 ms 12668 KB Output is correct
33 Correct 426 ms 10588 KB Output is correct
34 Correct 515 ms 12884 KB Output is correct
35 Correct 261 ms 11384 KB Output is correct
36 Correct 268 ms 12632 KB Output is correct
37 Correct 450 ms 11440 KB Output is correct
38 Correct 270 ms 10832 KB Output is correct
39 Correct 257 ms 6868 KB Output is correct
40 Correct 342 ms 7972 KB Output is correct
41 Correct 410 ms 12644 KB Output is correct
42 Correct 417 ms 12496 KB Output is correct
43 Correct 417 ms 12632 KB Output is correct
44 Correct 419 ms 12636 KB Output is correct
45 Correct 413 ms 12624 KB Output is correct
46 Correct 421 ms 12708 KB Output is correct
47 Correct 516 ms 11708 KB Output is correct
48 Correct 529 ms 12176 KB Output is correct
49 Correct 185 ms 9016 KB Output is correct
50 Correct 258 ms 11100 KB Output is correct
51 Correct 358 ms 12632 KB Output is correct
52 Correct 361 ms 12648 KB Output is correct
53 Correct 166 ms 10072 KB Output is correct
54 Correct 264 ms 12628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1046 ms 10200 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 1 ms 568 KB Output is correct
4 Correct 2 ms 824 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 824 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 828 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 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 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Incorrect 3 ms 604 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 1 ms 568 KB Output is correct
4 Correct 2 ms 824 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 824 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 828 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 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 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Incorrect 3 ms 604 KB Output isn't correct
22 Halted 0 ms 0 KB -