답안 #890545

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890545 2023-12-21T12:54:10 Z LucaIlie 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
1000 ms 460016 KB
#include <bits/stdc++.h>

using namespace std;

struct aaa {
    int t, c;
    long long k;
};

const int MAX_N = 3e5;
int bucket[MAX_N + 1], leftB[MAX_N + 1], rightB[MAX_N + 1];
long long queueIndexSize[MAX_N + 1], queueBucketSize[MAX_N + 1];
vector<aaa> queueIndex[MAX_N + 1], queueBucket[MAX_N + 1];

struct SegTree {
    struct info {
        long long sum, minn;

        info operator + ( info &x ) {
            info ans;

            ans.minn = min( minn, sum + x.minn );
            ans.sum = sum + x.sum;

            return ans;
        }
    };

    info lazy[4 * MAX_N];

    void propag( int v, int l, int r ) {
        if ( l != r ) {
            lazy[v * 2 + 1] = lazy[v * 2 + 1] + lazy[v];
            lazy[v * 2 + 2] = lazy[v * 2 + 2] + lazy[v];
            lazy[v] = { 0, 0 };
        }
    }

    void update( int v, int l, int r, int lu, int ru, int x ) {
        propag( v, l, r );

        if ( l > ru || r < lu )
            return;

        if ( lu <= l && r <= ru ) {
            info add = { x, min( x, 0 ) };
            lazy[v] = lazy[v] + add;
            propag( v, l, r );
            return;
        }

        int mid = (l + r) / 2;
        update( v * 2 + 1, l, mid, lu, ru, x );
        update( v * 2 + 2, mid + 1, r, lu, ru, x );
    }

    long long query( int v, int l, int r, int p ) {
        propag( v, l, r );

        if ( l == r )
            return lazy[v].sum - lazy[v].minn;

        int mid = (l + r) / 2;
        if ( p <= mid )
            return query( v * 2 + 1, l, mid, p );
        return query( v * 2 + 2, mid + 1, r, p );
    }
} qs;

signed main() {
    int n, m, q;

    cin >> n >> m >> q;

    int bs = sqrt( n );
    for ( int i = 1; i <= n; i++ ) {
        bucket[i] = i / bs;
        queueIndex[i].push_back( { -1, 0, 0 } );
    }
    for ( int b = 0; b * bs <= n; b++ ) {
        leftB[b] = b * bs;
        rightB[b] = min( n, (b + 1) * bs - 1 );
        queueBucket[b].push_back( { -1, 0, 0 } );
    }

    for ( int t = 0; t < q; t++ ) {
        int type;

        cin >> type;
        if ( type == 1 ) {
            int l, r, c, k;
            cin >> l >> r >> c >> k;
            qs.update( 0, 1, n, l, r, k );
            int bl = bucket[l], br = bucket[r];
            if ( bl == br ) {
                for ( int i = l; i <= r; i++ ) {
                    queueIndexSize[i] += k;
                    queueIndex[i].push_back( { t, c, queueIndexSize[i] } );
                }
            } else {
                for ( int i = l; i <= rightB[bl]; i++ ) {
                    queueIndexSize[i] += k;
                    queueIndex[i].push_back( { t, c, queueIndexSize[i] } );
                }
                for ( int i = leftB[br]; i <= r; i++ ) {
                    queueIndexSize[i] += k;
                    queueIndex[i].push_back( { t, c, queueIndexSize[i] } );
                }
                for ( int b = bl + 1; b <= br - 1; b++ ) {
                    queueBucketSize[b] += k;
                    queueBucket[b].push_back( { t, c, queueBucketSize[b] } );
                }
            }
        } else if ( type == 2 ) {
            int l, r, k;
            cin >> l >> r >> k;
            qs.update( 0, 1, n, l, r, -k );
        } else {
            int p;
            long long x;
            cin >> p >> x;
            int b = bucket[p];
            x += queueIndexSize[p] + queueBucketSize[b] - qs.query( 0, 1, n, p );

            int l = -1, r = t;
            while ( r - l > 1 ) {
                int mid = (l + r) / 2;

                int lp = 0, rp = queueIndex[p].size();
                while ( rp - lp > 1 ) {
                    int mp = (lp + rp) / 2;
                    if ( queueIndex[p][mp].t > mid )
                        rp = mp;
                    else
                        lp = mp;
                }

                int lb = 0, rb = queueBucket[b].size();
                while ( rb - lb > 1 ) {
                    int mb = (lb + rb) / 2;
                    if ( queueBucket[b][mb].t > mid )
                        rb = mb;
                    else
                        lb = mb;
                }

                long long k = (queueIndex[p].size() == 0 ? 0 : queueIndex[p][lp].k) + (queueBucket[b].size() == 0 ? 0 : queueBucket[b][lb].k);
                if ( k >= x )
                    r = mid;
                else
                    l = mid;
            }

            if ( r == t )
                cout << "0\n";
            else {
                int lp = 0, rp = queueIndex[p].size();
                while ( rp - lp > 1 ) {
                    int mp = (lp + rp) / 2;
                    if ( queueIndex[p][mp].t > r )
                        rp = mp;
                    else
                        lp = mp;
                }

                int lb = 0, rb = queueBucket[b].size();
                while ( rb - lb > 1 ) {
                    int mb = (lb + rb) / 2;
                    if ( queueBucket[b][mb].t > r )
                        rb = mb;
                    else
                        lb = mb;
                }

                if ( queueIndex[p][lp].t == r )
                    cout << queueIndex[p][lp].c << "\n";
                else if ( queueBucket[b][lb].t == r )
                    cout << queueBucket[b][lb].c << "\n";
                else
                    return 1;
            }
        }
    }

    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 17496 KB Output is correct
2 Correct 11 ms 17756 KB Output is correct
3 Correct 7 ms 18012 KB Output is correct
4 Correct 8 ms 18524 KB Output is correct
5 Correct 5 ms 16732 KB Output is correct
6 Correct 6 ms 16884 KB Output is correct
7 Correct 8 ms 17976 KB Output is correct
8 Correct 8 ms 18008 KB Output is correct
9 Correct 8 ms 18008 KB Output is correct
10 Correct 8 ms 18264 KB Output is correct
11 Correct 8 ms 18144 KB Output is correct
12 Correct 8 ms 18012 KB Output is correct
13 Correct 7 ms 18268 KB Output is correct
14 Correct 8 ms 18780 KB Output is correct
15 Correct 6 ms 17756 KB Output is correct
16 Correct 8 ms 18336 KB Output is correct
17 Correct 7 ms 17756 KB Output is correct
18 Correct 7 ms 18012 KB Output is correct
19 Correct 8 ms 17244 KB Output is correct
20 Correct 6 ms 17280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 17496 KB Output is correct
2 Correct 11 ms 17756 KB Output is correct
3 Correct 7 ms 18012 KB Output is correct
4 Correct 8 ms 18524 KB Output is correct
5 Correct 5 ms 16732 KB Output is correct
6 Correct 6 ms 16884 KB Output is correct
7 Correct 8 ms 17976 KB Output is correct
8 Correct 8 ms 18008 KB Output is correct
9 Correct 8 ms 18008 KB Output is correct
10 Correct 8 ms 18264 KB Output is correct
11 Correct 8 ms 18144 KB Output is correct
12 Correct 8 ms 18012 KB Output is correct
13 Correct 7 ms 18268 KB Output is correct
14 Correct 8 ms 18780 KB Output is correct
15 Correct 6 ms 17756 KB Output is correct
16 Correct 8 ms 18336 KB Output is correct
17 Correct 7 ms 17756 KB Output is correct
18 Correct 7 ms 18012 KB Output is correct
19 Correct 8 ms 17244 KB Output is correct
20 Correct 6 ms 17280 KB Output is correct
21 Correct 8 ms 17756 KB Output is correct
22 Correct 8 ms 17756 KB Output is correct
23 Correct 8 ms 18012 KB Output is correct
24 Correct 9 ms 18524 KB Output is correct
25 Correct 5 ms 16732 KB Output is correct
26 Correct 5 ms 16732 KB Output is correct
27 Correct 8 ms 18012 KB Output is correct
28 Correct 9 ms 18280 KB Output is correct
29 Correct 8 ms 18008 KB Output is correct
30 Correct 8 ms 18012 KB Output is correct
31 Correct 8 ms 18012 KB Output is correct
32 Correct 8 ms 17872 KB Output is correct
33 Correct 8 ms 18268 KB Output is correct
34 Correct 8 ms 18780 KB Output is correct
35 Correct 9 ms 18268 KB Output is correct
36 Correct 8 ms 18268 KB Output is correct
37 Correct 5 ms 16988 KB Output is correct
38 Correct 7 ms 17244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 24916 KB Output is correct
2 Correct 113 ms 26452 KB Output is correct
3 Correct 136 ms 27232 KB Output is correct
4 Correct 125 ms 27220 KB Output is correct
5 Correct 170 ms 30292 KB Output is correct
6 Correct 129 ms 30292 KB Output is correct
7 Correct 79 ms 17356 KB Output is correct
8 Correct 93 ms 17716 KB Output is correct
9 Correct 111 ms 25168 KB Output is correct
10 Correct 127 ms 25088 KB Output is correct
11 Correct 119 ms 25380 KB Output is correct
12 Correct 141 ms 25140 KB Output is correct
13 Correct 100 ms 26192 KB Output is correct
14 Correct 114 ms 27580 KB Output is correct
15 Correct 139 ms 29524 KB Output is correct
16 Correct 122 ms 30036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 460016 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 17496 KB Output is correct
2 Correct 11 ms 17756 KB Output is correct
3 Correct 7 ms 18012 KB Output is correct
4 Correct 8 ms 18524 KB Output is correct
5 Correct 5 ms 16732 KB Output is correct
6 Correct 6 ms 16884 KB Output is correct
7 Correct 8 ms 17976 KB Output is correct
8 Correct 8 ms 18008 KB Output is correct
9 Correct 8 ms 18008 KB Output is correct
10 Correct 8 ms 18264 KB Output is correct
11 Correct 8 ms 18144 KB Output is correct
12 Correct 8 ms 18012 KB Output is correct
13 Correct 7 ms 18268 KB Output is correct
14 Correct 8 ms 18780 KB Output is correct
15 Correct 6 ms 17756 KB Output is correct
16 Correct 8 ms 18336 KB Output is correct
17 Correct 7 ms 17756 KB Output is correct
18 Correct 7 ms 18012 KB Output is correct
19 Correct 8 ms 17244 KB Output is correct
20 Correct 6 ms 17280 KB Output is correct
21 Correct 112 ms 24916 KB Output is correct
22 Correct 113 ms 26452 KB Output is correct
23 Correct 136 ms 27232 KB Output is correct
24 Correct 125 ms 27220 KB Output is correct
25 Correct 170 ms 30292 KB Output is correct
26 Correct 129 ms 30292 KB Output is correct
27 Correct 79 ms 17356 KB Output is correct
28 Correct 93 ms 17716 KB Output is correct
29 Correct 111 ms 25168 KB Output is correct
30 Correct 127 ms 25088 KB Output is correct
31 Correct 119 ms 25380 KB Output is correct
32 Correct 141 ms 25140 KB Output is correct
33 Correct 100 ms 26192 KB Output is correct
34 Correct 114 ms 27580 KB Output is correct
35 Correct 139 ms 29524 KB Output is correct
36 Correct 122 ms 30036 KB Output is correct
37 Correct 415 ms 161676 KB Output is correct
38 Correct 494 ms 224064 KB Output is correct
39 Correct 58 ms 17968 KB Output is correct
40 Correct 83 ms 18272 KB Output is correct
41 Correct 481 ms 220816 KB Output is correct
42 Correct 502 ms 223412 KB Output is correct
43 Correct 499 ms 222532 KB Output is correct
44 Correct 526 ms 221112 KB Output is correct
45 Correct 500 ms 222168 KB Output is correct
46 Correct 510 ms 222848 KB Output is correct
47 Correct 517 ms 290888 KB Output is correct
48 Correct 447 ms 235068 KB Output is correct
49 Correct 368 ms 142532 KB Output is correct
50 Correct 400 ms 194120 KB Output is correct
51 Correct 492 ms 223328 KB Output is correct
52 Correct 483 ms 222652 KB Output is correct
53 Correct 92 ms 28896 KB Output is correct
54 Correct 141 ms 31628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 615 ms 235640 KB Output is correct
2 Correct 606 ms 248992 KB Output is correct
3 Correct 654 ms 269872 KB Output is correct
4 Correct 497 ms 204588 KB Output is correct
5 Correct 605 ms 248012 KB Output is correct
6 Correct 729 ms 285612 KB Output is correct
7 Correct 110 ms 18632 KB Output is correct
8 Correct 104 ms 18696 KB Output is correct
9 Correct 780 ms 404332 KB Output is correct
10 Correct 458 ms 225032 KB Output is correct
11 Correct 681 ms 338516 KB Output is correct
12 Correct 662 ms 330552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 17496 KB Output is correct
2 Correct 11 ms 17756 KB Output is correct
3 Correct 7 ms 18012 KB Output is correct
4 Correct 8 ms 18524 KB Output is correct
5 Correct 5 ms 16732 KB Output is correct
6 Correct 6 ms 16884 KB Output is correct
7 Correct 8 ms 17976 KB Output is correct
8 Correct 8 ms 18008 KB Output is correct
9 Correct 8 ms 18008 KB Output is correct
10 Correct 8 ms 18264 KB Output is correct
11 Correct 8 ms 18144 KB Output is correct
12 Correct 8 ms 18012 KB Output is correct
13 Correct 7 ms 18268 KB Output is correct
14 Correct 8 ms 18780 KB Output is correct
15 Correct 6 ms 17756 KB Output is correct
16 Correct 8 ms 18336 KB Output is correct
17 Correct 7 ms 17756 KB Output is correct
18 Correct 7 ms 18012 KB Output is correct
19 Correct 8 ms 17244 KB Output is correct
20 Correct 6 ms 17280 KB Output is correct
21 Correct 8 ms 17756 KB Output is correct
22 Correct 8 ms 17756 KB Output is correct
23 Correct 8 ms 18012 KB Output is correct
24 Correct 9 ms 18524 KB Output is correct
25 Correct 5 ms 16732 KB Output is correct
26 Correct 5 ms 16732 KB Output is correct
27 Correct 8 ms 18012 KB Output is correct
28 Correct 9 ms 18280 KB Output is correct
29 Correct 8 ms 18008 KB Output is correct
30 Correct 8 ms 18012 KB Output is correct
31 Correct 8 ms 18012 KB Output is correct
32 Correct 8 ms 17872 KB Output is correct
33 Correct 8 ms 18268 KB Output is correct
34 Correct 8 ms 18780 KB Output is correct
35 Correct 9 ms 18268 KB Output is correct
36 Correct 8 ms 18268 KB Output is correct
37 Correct 5 ms 16988 KB Output is correct
38 Correct 7 ms 17244 KB Output is correct
39 Correct 112 ms 24916 KB Output is correct
40 Correct 113 ms 26452 KB Output is correct
41 Correct 136 ms 27232 KB Output is correct
42 Correct 125 ms 27220 KB Output is correct
43 Correct 170 ms 30292 KB Output is correct
44 Correct 129 ms 30292 KB Output is correct
45 Correct 79 ms 17356 KB Output is correct
46 Correct 93 ms 17716 KB Output is correct
47 Correct 111 ms 25168 KB Output is correct
48 Correct 127 ms 25088 KB Output is correct
49 Correct 119 ms 25380 KB Output is correct
50 Correct 141 ms 25140 KB Output is correct
51 Correct 100 ms 26192 KB Output is correct
52 Correct 114 ms 27580 KB Output is correct
53 Correct 139 ms 29524 KB Output is correct
54 Correct 122 ms 30036 KB Output is correct
55 Correct 415 ms 161676 KB Output is correct
56 Correct 494 ms 224064 KB Output is correct
57 Correct 58 ms 17968 KB Output is correct
58 Correct 83 ms 18272 KB Output is correct
59 Correct 481 ms 220816 KB Output is correct
60 Correct 502 ms 223412 KB Output is correct
61 Correct 499 ms 222532 KB Output is correct
62 Correct 526 ms 221112 KB Output is correct
63 Correct 500 ms 222168 KB Output is correct
64 Correct 510 ms 222848 KB Output is correct
65 Correct 517 ms 290888 KB Output is correct
66 Correct 447 ms 235068 KB Output is correct
67 Correct 368 ms 142532 KB Output is correct
68 Correct 400 ms 194120 KB Output is correct
69 Correct 492 ms 223328 KB Output is correct
70 Correct 483 ms 222652 KB Output is correct
71 Correct 92 ms 28896 KB Output is correct
72 Correct 141 ms 31628 KB Output is correct
73 Correct 615 ms 235640 KB Output is correct
74 Correct 606 ms 248992 KB Output is correct
75 Correct 654 ms 269872 KB Output is correct
76 Correct 497 ms 204588 KB Output is correct
77 Correct 605 ms 248012 KB Output is correct
78 Correct 729 ms 285612 KB Output is correct
79 Correct 110 ms 18632 KB Output is correct
80 Correct 104 ms 18696 KB Output is correct
81 Correct 780 ms 404332 KB Output is correct
82 Correct 458 ms 225032 KB Output is correct
83 Correct 681 ms 338516 KB Output is correct
84 Correct 662 ms 330552 KB Output is correct
85 Correct 412 ms 154084 KB Output is correct
86 Correct 472 ms 187560 KB Output is correct
87 Correct 526 ms 246888 KB Output is correct
88 Correct 603 ms 284864 KB Output is correct
89 Correct 327 ms 139204 KB Output is correct
90 Correct 504 ms 224016 KB Output is correct
91 Correct 354 ms 157088 KB Output is correct
92 Correct 338 ms 150104 KB Output is correct
93 Correct 511 ms 223692 KB Output is correct
94 Correct 508 ms 224612 KB Output is correct
95 Correct 481 ms 209840 KB Output is correct
96 Correct 516 ms 226124 KB Output is correct
97 Correct 502 ms 223836 KB Output is correct
98 Correct 366 ms 167416 KB Output is correct
99 Correct 525 ms 294144 KB Output is correct
100 Correct 363 ms 190456 KB Output is correct
101 Correct 450 ms 234440 KB Output is correct
102 Correct 268 ms 109504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 17496 KB Output is correct
2 Correct 11 ms 17756 KB Output is correct
3 Correct 7 ms 18012 KB Output is correct
4 Correct 8 ms 18524 KB Output is correct
5 Correct 5 ms 16732 KB Output is correct
6 Correct 6 ms 16884 KB Output is correct
7 Correct 8 ms 17976 KB Output is correct
8 Correct 8 ms 18008 KB Output is correct
9 Correct 8 ms 18008 KB Output is correct
10 Correct 8 ms 18264 KB Output is correct
11 Correct 8 ms 18144 KB Output is correct
12 Correct 8 ms 18012 KB Output is correct
13 Correct 7 ms 18268 KB Output is correct
14 Correct 8 ms 18780 KB Output is correct
15 Correct 6 ms 17756 KB Output is correct
16 Correct 8 ms 18336 KB Output is correct
17 Correct 7 ms 17756 KB Output is correct
18 Correct 7 ms 18012 KB Output is correct
19 Correct 8 ms 17244 KB Output is correct
20 Correct 6 ms 17280 KB Output is correct
21 Correct 8 ms 17756 KB Output is correct
22 Correct 8 ms 17756 KB Output is correct
23 Correct 8 ms 18012 KB Output is correct
24 Correct 9 ms 18524 KB Output is correct
25 Correct 5 ms 16732 KB Output is correct
26 Correct 5 ms 16732 KB Output is correct
27 Correct 8 ms 18012 KB Output is correct
28 Correct 9 ms 18280 KB Output is correct
29 Correct 8 ms 18008 KB Output is correct
30 Correct 8 ms 18012 KB Output is correct
31 Correct 8 ms 18012 KB Output is correct
32 Correct 8 ms 17872 KB Output is correct
33 Correct 8 ms 18268 KB Output is correct
34 Correct 8 ms 18780 KB Output is correct
35 Correct 9 ms 18268 KB Output is correct
36 Correct 8 ms 18268 KB Output is correct
37 Correct 5 ms 16988 KB Output is correct
38 Correct 7 ms 17244 KB Output is correct
39 Correct 112 ms 24916 KB Output is correct
40 Correct 113 ms 26452 KB Output is correct
41 Correct 136 ms 27232 KB Output is correct
42 Correct 125 ms 27220 KB Output is correct
43 Correct 170 ms 30292 KB Output is correct
44 Correct 129 ms 30292 KB Output is correct
45 Correct 79 ms 17356 KB Output is correct
46 Correct 93 ms 17716 KB Output is correct
47 Correct 111 ms 25168 KB Output is correct
48 Correct 127 ms 25088 KB Output is correct
49 Correct 119 ms 25380 KB Output is correct
50 Correct 141 ms 25140 KB Output is correct
51 Correct 100 ms 26192 KB Output is correct
52 Correct 114 ms 27580 KB Output is correct
53 Correct 139 ms 29524 KB Output is correct
54 Correct 122 ms 30036 KB Output is correct
55 Execution timed out 1094 ms 460016 KB Time limit exceeded
56 Halted 0 ms 0 KB -