Submission #493381

# Submission time Handle Problem Language Result Execution time Memory
493381 2021-12-11T07:46:17 Z blue Food Court (JOI21_foodcourt) C++17
7 / 100
1000 ms 38744 KB
#include <iostream>
#include <vector>
using namespace std;

using vi = vector<int>;
using ll = long long;
using vll = vector<ll>;

const int mx = 250'000;
const ll INF = 1'000'000'000'000'000'000LL;

vi L(1+mx), R(1+mx), C(1+mx), A(1+mx);
vll K(1+mx), B(1+mx);
vi T(1+mx);

vi st[1+mx], en[1+mx], qr[1+mx];

vi ans(1+mx, 0);



struct segtree
{
    int l;
    int r;

    pair<ll, int> mn;
    ll lp = 0;

    segtree* left = NULL;
    segtree* right = NULL;


    segtree()
    {
        ;
    }

    segtree(int L, int R)
    {
        l = L;
        r = R;
        mn = {0, l};
        if(l == r) return;
        int m = (l+r)/2;
        left = new segtree(l, m);
        right = new segtree(m+1, r);
    }

    void add(int L, int R, ll V)
    {
        if(r < L || R < l) return;
        else if(L <= l && r <= V)
        {
            lp += V;
            mn.first += V;
        }
        else
        {
            left->add(L, R, V);
            right->add(L, R, V);
            mn = min(left->mn, right->mn);
            mn.first += lp;
        }
    }

    pair<ll, int> rangemin(int L, int R)
    {
        if(R < l || r < L) return {INF, -1};
        else if(L <= l && r <= R) return mn;
        else
        {
            auto res = min(left->rangemin(L, R), right->rangemin(L, R));
            res.first += lp;
            return res;
        }
    }
};



int main()
{
    int N, M, Q;
    cin >> N >> M >> Q;

    for(int j = 1; j <= Q; j++)
    {
        cin >> T[j];
        if(T[j] == 1) cin >> L[j] >> R[j] >> C[j] >> K[j];
        else if(T[j] == 2)
        {
            cin >> L[j] >> R[j] >> K[j];
            K[j] *= -1;
        }
        else cin >> A[j] >> B[j];

        if(T[j] <= 2)
        {
            st[L[j]].push_back(j);
            en[R[j]].push_back(j);
        }
        else qr[A[j]].push_back(j);
    }

    vll S(1+Q, 0);

    vi ans(1+Q, 0);

    // segtree ST(0, Q);

    for(int i = 1; i <= N; i++)
    {
        for(int o: st[i])
        {
            S[o] = K[o];
            // ST.add(o, Q, +K[o]);
        }

        for(int q: qr[i])
        {
            pair<ll, int> pos{0, 0};
            ll curr_sum = 0;
            for(int j = 1; j <= q-1; j++)
            {
                curr_sum += S[j];
                pos = min(pos, {curr_sum, j});
            }

            int p = pos.second;

            // p = ST.rangemin(0, q-1).second;

            ll minus_sum = 0;
            for(int j = p+1; j <= q; j++)
                if(S[j] < 0)
                    minus_sum += -S[j];

            // cerr << "p = " << p << '\n';
            // cerr << "total loss = " << minus_sum << '\n';

            ll plus_sum = 0;
            for(int j = p+1; j <= q; j++)
            {
                if(S[j] > 0)
                    plus_sum += S[j];

                if(plus_sum >= minus_sum + B[q])
                {
                    ans[q] = C[j];
                    break;
                }
            }
        }

        for(int o: en[i])
        {
            S[o] = 0;
            // ST.add(o, Q, -K[o]);
        }
    }



    for(int q = 1; q <= Q; q++)
        if(T[q] == 3)
            cout << ans[q] << '\n';
    // cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 27752 KB Output is correct
2 Correct 20 ms 27724 KB Output is correct
3 Correct 17 ms 27788 KB Output is correct
4 Correct 17 ms 27784 KB Output is correct
5 Correct 16 ms 27768 KB Output is correct
6 Correct 17 ms 27716 KB Output is correct
7 Correct 23 ms 27800 KB Output is correct
8 Correct 17 ms 27724 KB Output is correct
9 Correct 17 ms 27724 KB Output is correct
10 Correct 17 ms 27724 KB Output is correct
11 Correct 18 ms 27776 KB Output is correct
12 Correct 20 ms 27716 KB Output is correct
13 Correct 16 ms 27700 KB Output is correct
14 Correct 18 ms 27724 KB Output is correct
15 Correct 17 ms 27712 KB Output is correct
16 Correct 16 ms 27748 KB Output is correct
17 Correct 16 ms 27724 KB Output is correct
18 Correct 25 ms 27776 KB Output is correct
19 Correct 16 ms 27780 KB Output is correct
20 Correct 19 ms 27740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 27752 KB Output is correct
2 Correct 20 ms 27724 KB Output is correct
3 Correct 17 ms 27788 KB Output is correct
4 Correct 17 ms 27784 KB Output is correct
5 Correct 16 ms 27768 KB Output is correct
6 Correct 17 ms 27716 KB Output is correct
7 Correct 23 ms 27800 KB Output is correct
8 Correct 17 ms 27724 KB Output is correct
9 Correct 17 ms 27724 KB Output is correct
10 Correct 17 ms 27724 KB Output is correct
11 Correct 18 ms 27776 KB Output is correct
12 Correct 20 ms 27716 KB Output is correct
13 Correct 16 ms 27700 KB Output is correct
14 Correct 18 ms 27724 KB Output is correct
15 Correct 17 ms 27712 KB Output is correct
16 Correct 16 ms 27748 KB Output is correct
17 Correct 16 ms 27724 KB Output is correct
18 Correct 25 ms 27776 KB Output is correct
19 Correct 16 ms 27780 KB Output is correct
20 Correct 19 ms 27740 KB Output is correct
21 Correct 25 ms 27724 KB Output is correct
22 Correct 17 ms 27724 KB Output is correct
23 Correct 24 ms 27724 KB Output is correct
24 Correct 18 ms 27724 KB Output is correct
25 Correct 16 ms 27684 KB Output is correct
26 Correct 19 ms 27748 KB Output is correct
27 Correct 20 ms 27928 KB Output is correct
28 Correct 18 ms 27724 KB Output is correct
29 Correct 19 ms 27816 KB Output is correct
30 Correct 17 ms 27724 KB Output is correct
31 Correct 17 ms 27764 KB Output is correct
32 Correct 17 ms 27776 KB Output is correct
33 Correct 18 ms 27716 KB Output is correct
34 Correct 18 ms 27788 KB Output is correct
35 Correct 17 ms 27724 KB Output is correct
36 Correct 24 ms 27728 KB Output is correct
37 Correct 15 ms 27748 KB Output is correct
38 Correct 16 ms 27852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1084 ms 31024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 38744 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 27752 KB Output is correct
2 Correct 20 ms 27724 KB Output is correct
3 Correct 17 ms 27788 KB Output is correct
4 Correct 17 ms 27784 KB Output is correct
5 Correct 16 ms 27768 KB Output is correct
6 Correct 17 ms 27716 KB Output is correct
7 Correct 23 ms 27800 KB Output is correct
8 Correct 17 ms 27724 KB Output is correct
9 Correct 17 ms 27724 KB Output is correct
10 Correct 17 ms 27724 KB Output is correct
11 Correct 18 ms 27776 KB Output is correct
12 Correct 20 ms 27716 KB Output is correct
13 Correct 16 ms 27700 KB Output is correct
14 Correct 18 ms 27724 KB Output is correct
15 Correct 17 ms 27712 KB Output is correct
16 Correct 16 ms 27748 KB Output is correct
17 Correct 16 ms 27724 KB Output is correct
18 Correct 25 ms 27776 KB Output is correct
19 Correct 16 ms 27780 KB Output is correct
20 Correct 19 ms 27740 KB Output is correct
21 Execution timed out 1084 ms 31024 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 30364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 27752 KB Output is correct
2 Correct 20 ms 27724 KB Output is correct
3 Correct 17 ms 27788 KB Output is correct
4 Correct 17 ms 27784 KB Output is correct
5 Correct 16 ms 27768 KB Output is correct
6 Correct 17 ms 27716 KB Output is correct
7 Correct 23 ms 27800 KB Output is correct
8 Correct 17 ms 27724 KB Output is correct
9 Correct 17 ms 27724 KB Output is correct
10 Correct 17 ms 27724 KB Output is correct
11 Correct 18 ms 27776 KB Output is correct
12 Correct 20 ms 27716 KB Output is correct
13 Correct 16 ms 27700 KB Output is correct
14 Correct 18 ms 27724 KB Output is correct
15 Correct 17 ms 27712 KB Output is correct
16 Correct 16 ms 27748 KB Output is correct
17 Correct 16 ms 27724 KB Output is correct
18 Correct 25 ms 27776 KB Output is correct
19 Correct 16 ms 27780 KB Output is correct
20 Correct 19 ms 27740 KB Output is correct
21 Correct 25 ms 27724 KB Output is correct
22 Correct 17 ms 27724 KB Output is correct
23 Correct 24 ms 27724 KB Output is correct
24 Correct 18 ms 27724 KB Output is correct
25 Correct 16 ms 27684 KB Output is correct
26 Correct 19 ms 27748 KB Output is correct
27 Correct 20 ms 27928 KB Output is correct
28 Correct 18 ms 27724 KB Output is correct
29 Correct 19 ms 27816 KB Output is correct
30 Correct 17 ms 27724 KB Output is correct
31 Correct 17 ms 27764 KB Output is correct
32 Correct 17 ms 27776 KB Output is correct
33 Correct 18 ms 27716 KB Output is correct
34 Correct 18 ms 27788 KB Output is correct
35 Correct 17 ms 27724 KB Output is correct
36 Correct 24 ms 27728 KB Output is correct
37 Correct 15 ms 27748 KB Output is correct
38 Correct 16 ms 27852 KB Output is correct
39 Execution timed out 1084 ms 31024 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 27752 KB Output is correct
2 Correct 20 ms 27724 KB Output is correct
3 Correct 17 ms 27788 KB Output is correct
4 Correct 17 ms 27784 KB Output is correct
5 Correct 16 ms 27768 KB Output is correct
6 Correct 17 ms 27716 KB Output is correct
7 Correct 23 ms 27800 KB Output is correct
8 Correct 17 ms 27724 KB Output is correct
9 Correct 17 ms 27724 KB Output is correct
10 Correct 17 ms 27724 KB Output is correct
11 Correct 18 ms 27776 KB Output is correct
12 Correct 20 ms 27716 KB Output is correct
13 Correct 16 ms 27700 KB Output is correct
14 Correct 18 ms 27724 KB Output is correct
15 Correct 17 ms 27712 KB Output is correct
16 Correct 16 ms 27748 KB Output is correct
17 Correct 16 ms 27724 KB Output is correct
18 Correct 25 ms 27776 KB Output is correct
19 Correct 16 ms 27780 KB Output is correct
20 Correct 19 ms 27740 KB Output is correct
21 Correct 25 ms 27724 KB Output is correct
22 Correct 17 ms 27724 KB Output is correct
23 Correct 24 ms 27724 KB Output is correct
24 Correct 18 ms 27724 KB Output is correct
25 Correct 16 ms 27684 KB Output is correct
26 Correct 19 ms 27748 KB Output is correct
27 Correct 20 ms 27928 KB Output is correct
28 Correct 18 ms 27724 KB Output is correct
29 Correct 19 ms 27816 KB Output is correct
30 Correct 17 ms 27724 KB Output is correct
31 Correct 17 ms 27764 KB Output is correct
32 Correct 17 ms 27776 KB Output is correct
33 Correct 18 ms 27716 KB Output is correct
34 Correct 18 ms 27788 KB Output is correct
35 Correct 17 ms 27724 KB Output is correct
36 Correct 24 ms 27728 KB Output is correct
37 Correct 15 ms 27748 KB Output is correct
38 Correct 16 ms 27852 KB Output is correct
39 Execution timed out 1084 ms 31024 KB Time limit exceeded
40 Halted 0 ms 0 KB -