답안 #493408

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493408 2021-12-11T08:28:10 Z blue 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
1000 ms 71216 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 <= R)
        {
            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;
        }
    }
};

struct BIT
{
    int Z;
    vll arr;

    BIT()
    {
        ;
    }

    BIT(int z)
    {
        Z = z;
        arr = vll(1+z, 0);
    }

    void add(int i, ll v)
    {
        for(int j = i; j <= Z; j += j&-j)
            arr[j] += v;
    }

    ll prefsum(int i)
    {
        ll ans = 0;
        for(int j = i; j >= 1; j -= j&-j)
            ans += arr[j];
        return ans;
    }
};



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);
    BIT plus_sum(1+Q), minus_sum(1+Q);

    for(int i = 1; i <= N; i++)
    {
        for(int o: st[i])
        {
            S[o] = K[o];
            ST.add(o, Q, +K[o]);
            if(K[o] > 0)
                plus_sum.add(o, +K[o]);
            else
                minus_sum.add(o, -K[o]);
        }

        for(int q: qr[i])
        {
            int p = ST.rangemin(0, q-1).second;

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

            // 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 >= min_sum + B[q])
                {
                    ans[q] = C[j];
                    break;
                }
            }
        }

        for(int o: en[i])
        {
            S[o] = 0;
            ST.add(o, Q, -K[o]);
            if(K[o] > 0)
                plus_sum.add(o, -K[o]);
            else
                minus_sum.add(o, +K[o]);
        }
    }



    for(int q = 1; q <= Q; q++)
        if(T[q] == 3)
            cout << ans[q] << '\n';
    // cout << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 27980 KB Output is correct
2 Correct 17 ms 28016 KB Output is correct
3 Correct 15 ms 27980 KB Output is correct
4 Correct 17 ms 27980 KB Output is correct
5 Correct 17 ms 27928 KB Output is correct
6 Correct 15 ms 27980 KB Output is correct
7 Correct 16 ms 27980 KB Output is correct
8 Correct 17 ms 27980 KB Output is correct
9 Correct 15 ms 28108 KB Output is correct
10 Correct 17 ms 28024 KB Output is correct
11 Correct 16 ms 27996 KB Output is correct
12 Correct 15 ms 28080 KB Output is correct
13 Correct 15 ms 27980 KB Output is correct
14 Correct 15 ms 27996 KB Output is correct
15 Correct 17 ms 27840 KB Output is correct
16 Correct 15 ms 28004 KB Output is correct
17 Correct 15 ms 27972 KB Output is correct
18 Correct 16 ms 28108 KB Output is correct
19 Correct 16 ms 27980 KB Output is correct
20 Correct 16 ms 28096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 27980 KB Output is correct
2 Correct 17 ms 28016 KB Output is correct
3 Correct 15 ms 27980 KB Output is correct
4 Correct 17 ms 27980 KB Output is correct
5 Correct 17 ms 27928 KB Output is correct
6 Correct 15 ms 27980 KB Output is correct
7 Correct 16 ms 27980 KB Output is correct
8 Correct 17 ms 27980 KB Output is correct
9 Correct 15 ms 28108 KB Output is correct
10 Correct 17 ms 28024 KB Output is correct
11 Correct 16 ms 27996 KB Output is correct
12 Correct 15 ms 28080 KB Output is correct
13 Correct 15 ms 27980 KB Output is correct
14 Correct 15 ms 27996 KB Output is correct
15 Correct 17 ms 27840 KB Output is correct
16 Correct 15 ms 28004 KB Output is correct
17 Correct 15 ms 27972 KB Output is correct
18 Correct 16 ms 28108 KB Output is correct
19 Correct 16 ms 27980 KB Output is correct
20 Correct 16 ms 28096 KB Output is correct
21 Correct 18 ms 27980 KB Output is correct
22 Correct 16 ms 27980 KB Output is correct
23 Correct 18 ms 27980 KB Output is correct
24 Correct 16 ms 28056 KB Output is correct
25 Correct 16 ms 28008 KB Output is correct
26 Correct 17 ms 28012 KB Output is correct
27 Correct 19 ms 28012 KB Output is correct
28 Correct 16 ms 28008 KB Output is correct
29 Correct 18 ms 28104 KB Output is correct
30 Correct 16 ms 27980 KB Output is correct
31 Correct 16 ms 27980 KB Output is correct
32 Correct 17 ms 27980 KB Output is correct
33 Correct 15 ms 28028 KB Output is correct
34 Correct 15 ms 27980 KB Output is correct
35 Correct 16 ms 28036 KB Output is correct
36 Correct 16 ms 28024 KB Output is correct
37 Correct 14 ms 27992 KB Output is correct
38 Correct 16 ms 27980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 40084 KB Output is correct
2 Correct 159 ms 40336 KB Output is correct
3 Correct 154 ms 40260 KB Output is correct
4 Correct 151 ms 40300 KB Output is correct
5 Correct 161 ms 40304 KB Output is correct
6 Correct 177 ms 40380 KB Output is correct
7 Correct 83 ms 37468 KB Output is correct
8 Correct 82 ms 37748 KB Output is correct
9 Correct 166 ms 40256 KB Output is correct
10 Correct 169 ms 40212 KB Output is correct
11 Correct 160 ms 40256 KB Output is correct
12 Correct 157 ms 40172 KB Output is correct
13 Correct 155 ms 38856 KB Output is correct
14 Correct 153 ms 40228 KB Output is correct
15 Correct 156 ms 39876 KB Output is correct
16 Correct 172 ms 40280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 71216 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 27980 KB Output is correct
2 Correct 17 ms 28016 KB Output is correct
3 Correct 15 ms 27980 KB Output is correct
4 Correct 17 ms 27980 KB Output is correct
5 Correct 17 ms 27928 KB Output is correct
6 Correct 15 ms 27980 KB Output is correct
7 Correct 16 ms 27980 KB Output is correct
8 Correct 17 ms 27980 KB Output is correct
9 Correct 15 ms 28108 KB Output is correct
10 Correct 17 ms 28024 KB Output is correct
11 Correct 16 ms 27996 KB Output is correct
12 Correct 15 ms 28080 KB Output is correct
13 Correct 15 ms 27980 KB Output is correct
14 Correct 15 ms 27996 KB Output is correct
15 Correct 17 ms 27840 KB Output is correct
16 Correct 15 ms 28004 KB Output is correct
17 Correct 15 ms 27972 KB Output is correct
18 Correct 16 ms 28108 KB Output is correct
19 Correct 16 ms 27980 KB Output is correct
20 Correct 16 ms 28096 KB Output is correct
21 Correct 151 ms 40084 KB Output is correct
22 Correct 159 ms 40336 KB Output is correct
23 Correct 154 ms 40260 KB Output is correct
24 Correct 151 ms 40300 KB Output is correct
25 Correct 161 ms 40304 KB Output is correct
26 Correct 177 ms 40380 KB Output is correct
27 Correct 83 ms 37468 KB Output is correct
28 Correct 82 ms 37748 KB Output is correct
29 Correct 166 ms 40256 KB Output is correct
30 Correct 169 ms 40212 KB Output is correct
31 Correct 160 ms 40256 KB Output is correct
32 Correct 157 ms 40172 KB Output is correct
33 Correct 155 ms 38856 KB Output is correct
34 Correct 153 ms 40228 KB Output is correct
35 Correct 156 ms 39876 KB Output is correct
36 Correct 172 ms 40280 KB Output is correct
37 Correct 376 ms 38892 KB Output is correct
38 Correct 349 ms 37588 KB Output is correct
39 Correct 224 ms 36312 KB Output is correct
40 Correct 263 ms 37568 KB Output is correct
41 Correct 509 ms 40044 KB Output is correct
42 Correct 546 ms 39988 KB Output is correct
43 Correct 314 ms 39976 KB Output is correct
44 Correct 465 ms 39988 KB Output is correct
45 Correct 517 ms 39900 KB Output is correct
46 Correct 329 ms 39856 KB Output is correct
47 Correct 524 ms 38652 KB Output is correct
48 Correct 373 ms 39748 KB Output is correct
49 Correct 117 ms 37096 KB Output is correct
50 Correct 155 ms 39024 KB Output is correct
51 Correct 158 ms 41148 KB Output is correct
52 Correct 161 ms 41104 KB Output is correct
53 Correct 128 ms 38540 KB Output is correct
54 Correct 157 ms 41524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 653 ms 38788 KB Output is correct
2 Correct 789 ms 41428 KB Output is correct
3 Correct 799 ms 41692 KB Output is correct
4 Correct 433 ms 37608 KB Output is correct
5 Correct 629 ms 39748 KB Output is correct
6 Correct 780 ms 41668 KB Output is correct
7 Correct 582 ms 38164 KB Output is correct
8 Correct 512 ms 37516 KB Output is correct
9 Correct 757 ms 40388 KB Output is correct
10 Correct 400 ms 36552 KB Output is correct
11 Correct 768 ms 40560 KB Output is correct
12 Correct 777 ms 40552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 27980 KB Output is correct
2 Correct 17 ms 28016 KB Output is correct
3 Correct 15 ms 27980 KB Output is correct
4 Correct 17 ms 27980 KB Output is correct
5 Correct 17 ms 27928 KB Output is correct
6 Correct 15 ms 27980 KB Output is correct
7 Correct 16 ms 27980 KB Output is correct
8 Correct 17 ms 27980 KB Output is correct
9 Correct 15 ms 28108 KB Output is correct
10 Correct 17 ms 28024 KB Output is correct
11 Correct 16 ms 27996 KB Output is correct
12 Correct 15 ms 28080 KB Output is correct
13 Correct 15 ms 27980 KB Output is correct
14 Correct 15 ms 27996 KB Output is correct
15 Correct 17 ms 27840 KB Output is correct
16 Correct 15 ms 28004 KB Output is correct
17 Correct 15 ms 27972 KB Output is correct
18 Correct 16 ms 28108 KB Output is correct
19 Correct 16 ms 27980 KB Output is correct
20 Correct 16 ms 28096 KB Output is correct
21 Correct 18 ms 27980 KB Output is correct
22 Correct 16 ms 27980 KB Output is correct
23 Correct 18 ms 27980 KB Output is correct
24 Correct 16 ms 28056 KB Output is correct
25 Correct 16 ms 28008 KB Output is correct
26 Correct 17 ms 28012 KB Output is correct
27 Correct 19 ms 28012 KB Output is correct
28 Correct 16 ms 28008 KB Output is correct
29 Correct 18 ms 28104 KB Output is correct
30 Correct 16 ms 27980 KB Output is correct
31 Correct 16 ms 27980 KB Output is correct
32 Correct 17 ms 27980 KB Output is correct
33 Correct 15 ms 28028 KB Output is correct
34 Correct 15 ms 27980 KB Output is correct
35 Correct 16 ms 28036 KB Output is correct
36 Correct 16 ms 28024 KB Output is correct
37 Correct 14 ms 27992 KB Output is correct
38 Correct 16 ms 27980 KB Output is correct
39 Correct 151 ms 40084 KB Output is correct
40 Correct 159 ms 40336 KB Output is correct
41 Correct 154 ms 40260 KB Output is correct
42 Correct 151 ms 40300 KB Output is correct
43 Correct 161 ms 40304 KB Output is correct
44 Correct 177 ms 40380 KB Output is correct
45 Correct 83 ms 37468 KB Output is correct
46 Correct 82 ms 37748 KB Output is correct
47 Correct 166 ms 40256 KB Output is correct
48 Correct 169 ms 40212 KB Output is correct
49 Correct 160 ms 40256 KB Output is correct
50 Correct 157 ms 40172 KB Output is correct
51 Correct 155 ms 38856 KB Output is correct
52 Correct 153 ms 40228 KB Output is correct
53 Correct 156 ms 39876 KB Output is correct
54 Correct 172 ms 40280 KB Output is correct
55 Correct 376 ms 38892 KB Output is correct
56 Correct 349 ms 37588 KB Output is correct
57 Correct 224 ms 36312 KB Output is correct
58 Correct 263 ms 37568 KB Output is correct
59 Correct 509 ms 40044 KB Output is correct
60 Correct 546 ms 39988 KB Output is correct
61 Correct 314 ms 39976 KB Output is correct
62 Correct 465 ms 39988 KB Output is correct
63 Correct 517 ms 39900 KB Output is correct
64 Correct 329 ms 39856 KB Output is correct
65 Correct 524 ms 38652 KB Output is correct
66 Correct 373 ms 39748 KB Output is correct
67 Correct 117 ms 37096 KB Output is correct
68 Correct 155 ms 39024 KB Output is correct
69 Correct 158 ms 41148 KB Output is correct
70 Correct 161 ms 41104 KB Output is correct
71 Correct 128 ms 38540 KB Output is correct
72 Correct 157 ms 41524 KB Output is correct
73 Correct 653 ms 38788 KB Output is correct
74 Correct 789 ms 41428 KB Output is correct
75 Correct 799 ms 41692 KB Output is correct
76 Correct 433 ms 37608 KB Output is correct
77 Correct 629 ms 39748 KB Output is correct
78 Correct 780 ms 41668 KB Output is correct
79 Correct 582 ms 38164 KB Output is correct
80 Correct 512 ms 37516 KB Output is correct
81 Correct 757 ms 40388 KB Output is correct
82 Correct 400 ms 36552 KB Output is correct
83 Correct 768 ms 40560 KB Output is correct
84 Correct 777 ms 40552 KB Output is correct
85 Correct 368 ms 40252 KB Output is correct
86 Correct 595 ms 41608 KB Output is correct
87 Correct 429 ms 39892 KB Output is correct
88 Correct 516 ms 41592 KB Output is correct
89 Correct 260 ms 37060 KB Output is correct
90 Correct 538 ms 41468 KB Output is correct
91 Correct 243 ms 38876 KB Output is correct
92 Correct 244 ms 38364 KB Output is correct
93 Correct 535 ms 41440 KB Output is correct
94 Correct 505 ms 41472 KB Output is correct
95 Correct 535 ms 41104 KB Output is correct
96 Correct 543 ms 41448 KB Output is correct
97 Correct 261 ms 41516 KB Output is correct
98 Correct 295 ms 39372 KB Output is correct
99 Correct 695 ms 39960 KB Output is correct
100 Correct 288 ms 38280 KB Output is correct
101 Correct 433 ms 40372 KB Output is correct
102 Correct 449 ms 42184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 27980 KB Output is correct
2 Correct 17 ms 28016 KB Output is correct
3 Correct 15 ms 27980 KB Output is correct
4 Correct 17 ms 27980 KB Output is correct
5 Correct 17 ms 27928 KB Output is correct
6 Correct 15 ms 27980 KB Output is correct
7 Correct 16 ms 27980 KB Output is correct
8 Correct 17 ms 27980 KB Output is correct
9 Correct 15 ms 28108 KB Output is correct
10 Correct 17 ms 28024 KB Output is correct
11 Correct 16 ms 27996 KB Output is correct
12 Correct 15 ms 28080 KB Output is correct
13 Correct 15 ms 27980 KB Output is correct
14 Correct 15 ms 27996 KB Output is correct
15 Correct 17 ms 27840 KB Output is correct
16 Correct 15 ms 28004 KB Output is correct
17 Correct 15 ms 27972 KB Output is correct
18 Correct 16 ms 28108 KB Output is correct
19 Correct 16 ms 27980 KB Output is correct
20 Correct 16 ms 28096 KB Output is correct
21 Correct 18 ms 27980 KB Output is correct
22 Correct 16 ms 27980 KB Output is correct
23 Correct 18 ms 27980 KB Output is correct
24 Correct 16 ms 28056 KB Output is correct
25 Correct 16 ms 28008 KB Output is correct
26 Correct 17 ms 28012 KB Output is correct
27 Correct 19 ms 28012 KB Output is correct
28 Correct 16 ms 28008 KB Output is correct
29 Correct 18 ms 28104 KB Output is correct
30 Correct 16 ms 27980 KB Output is correct
31 Correct 16 ms 27980 KB Output is correct
32 Correct 17 ms 27980 KB Output is correct
33 Correct 15 ms 28028 KB Output is correct
34 Correct 15 ms 27980 KB Output is correct
35 Correct 16 ms 28036 KB Output is correct
36 Correct 16 ms 28024 KB Output is correct
37 Correct 14 ms 27992 KB Output is correct
38 Correct 16 ms 27980 KB Output is correct
39 Correct 151 ms 40084 KB Output is correct
40 Correct 159 ms 40336 KB Output is correct
41 Correct 154 ms 40260 KB Output is correct
42 Correct 151 ms 40300 KB Output is correct
43 Correct 161 ms 40304 KB Output is correct
44 Correct 177 ms 40380 KB Output is correct
45 Correct 83 ms 37468 KB Output is correct
46 Correct 82 ms 37748 KB Output is correct
47 Correct 166 ms 40256 KB Output is correct
48 Correct 169 ms 40212 KB Output is correct
49 Correct 160 ms 40256 KB Output is correct
50 Correct 157 ms 40172 KB Output is correct
51 Correct 155 ms 38856 KB Output is correct
52 Correct 153 ms 40228 KB Output is correct
53 Correct 156 ms 39876 KB Output is correct
54 Correct 172 ms 40280 KB Output is correct
55 Execution timed out 1094 ms 71216 KB Time limit exceeded
56 Halted 0 ms 0 KB -