Submission #891187

# Submission time Handle Problem Language Result Execution time Memory
891187 2023-12-22T10:32:50 Z LucaIlie Food Court (JOI21_foodcourt) C++17
68 / 100
1000 ms 88068 KB
#include <bits/stdc++.h>

using namespace std;

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

const int MAX_N = 3e5;
int group[MAX_N];

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

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

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

            return ans;
        }
    };

    info lazy[4 * MAX_N];
    long long size[4 * MAX_N];
    vector<aaa> q[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 init( int v, int l, int r ) {
        q[v].push_back( { -1, 0, 0 } );
        if ( l == r )
            return;
        int mid = (l + r) / 2;
        init( v * 2 + 1, l, mid );
        init( v * 2 + 2, mid + 1, r );
    }
    void update( int v, int l, int r, int lu, int ru, int k, int c, int t ) {
        propag( v, l, r );

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

        if ( lu <= l && r <= ru ) {
            if ( k > 0 ) {
                size[v] += k;
                q[v].push_back( { t, c, size[v] } );
            }
            info add = { max( k, 0 ), k,  min( k, 0 ) };
            lazy[v] = lazy[v] + add;
            propag( v, l, r );
            return;
        }

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

    vector<int> ans;
    long long query( int v, int l, int r, int p ) {
        if ( v == 0 )
            ans.clear();
        ans.push_back( v );
        propag( v, l, r );

        if ( l == r )
            return lazy[v].tot - (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() {
    ios_base::sync_with_stdio( false );
    cin.tie( NULL );
    cout.tie( NULL );

    int n, m, q;

    cin >> n >> m >> q;
    qs.init( 0, 1, n );
    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, c, t );
            group[t] = c;
        } else if ( type == 2 ) {
            int l, r, k;
            cin >> l >> r >> k;
            qs.update( 0, 1, n, l, r, -k, 0, t );
        } else {
            int p;
            long long x;
            cin >> p >> x;
            x += qs.query( 0, 1, n, p );
            vector<int> vert = qs.ans;

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

                long long k = 0;
                for ( int v: vert ) {
                    int lp = 0, rp = qs.q[v].size();
                    while ( rp - lp > 1 ) {
                        int mp = (lp + rp) / 2;
                        if ( qs.q[v][mp].t > mid )
                            rp = mp;
                        else
                            lp = mp;
                    }
                    k += qs.q[v][lp].k;
                }

                if ( k >= x )
                    r = mid;
                else
                    l = mid;
            }

            cout << group[r] << "\n";
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29528 KB Output is correct
2 Correct 9 ms 29532 KB Output is correct
3 Correct 8 ms 29376 KB Output is correct
4 Correct 9 ms 29532 KB Output is correct
5 Correct 7 ms 29020 KB Output is correct
6 Correct 7 ms 29020 KB Output is correct
7 Correct 9 ms 29396 KB Output is correct
8 Correct 11 ms 29532 KB Output is correct
9 Correct 9 ms 29532 KB Output is correct
10 Correct 9 ms 29532 KB Output is correct
11 Correct 10 ms 29660 KB Output is correct
12 Correct 10 ms 29532 KB Output is correct
13 Correct 7 ms 29276 KB Output is correct
14 Correct 7 ms 29272 KB Output is correct
15 Correct 7 ms 29528 KB Output is correct
16 Correct 8 ms 29532 KB Output is correct
17 Correct 9 ms 29532 KB Output is correct
18 Correct 9 ms 29532 KB Output is correct
19 Correct 8 ms 29532 KB Output is correct
20 Correct 8 ms 29400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29528 KB Output is correct
2 Correct 9 ms 29532 KB Output is correct
3 Correct 8 ms 29376 KB Output is correct
4 Correct 9 ms 29532 KB Output is correct
5 Correct 7 ms 29020 KB Output is correct
6 Correct 7 ms 29020 KB Output is correct
7 Correct 9 ms 29396 KB Output is correct
8 Correct 11 ms 29532 KB Output is correct
9 Correct 9 ms 29532 KB Output is correct
10 Correct 9 ms 29532 KB Output is correct
11 Correct 10 ms 29660 KB Output is correct
12 Correct 10 ms 29532 KB Output is correct
13 Correct 7 ms 29276 KB Output is correct
14 Correct 7 ms 29272 KB Output is correct
15 Correct 7 ms 29528 KB Output is correct
16 Correct 8 ms 29532 KB Output is correct
17 Correct 9 ms 29532 KB Output is correct
18 Correct 9 ms 29532 KB Output is correct
19 Correct 8 ms 29532 KB Output is correct
20 Correct 8 ms 29400 KB Output is correct
21 Correct 9 ms 29532 KB Output is correct
22 Correct 9 ms 29592 KB Output is correct
23 Correct 9 ms 29632 KB Output is correct
24 Correct 9 ms 29532 KB Output is correct
25 Correct 7 ms 29268 KB Output is correct
26 Correct 7 ms 29020 KB Output is correct
27 Correct 10 ms 29528 KB Output is correct
28 Correct 9 ms 29528 KB Output is correct
29 Correct 9 ms 29532 KB Output is correct
30 Correct 9 ms 29532 KB Output is correct
31 Correct 9 ms 29532 KB Output is correct
32 Correct 9 ms 29532 KB Output is correct
33 Correct 7 ms 29276 KB Output is correct
34 Correct 8 ms 29388 KB Output is correct
35 Correct 8 ms 29532 KB Output is correct
36 Correct 9 ms 29532 KB Output is correct
37 Correct 8 ms 29784 KB Output is correct
38 Correct 8 ms 29532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 39252 KB Output is correct
2 Correct 82 ms 39760 KB Output is correct
3 Correct 88 ms 39756 KB Output is correct
4 Correct 96 ms 39636 KB Output is correct
5 Correct 104 ms 40460 KB Output is correct
6 Correct 84 ms 40512 KB Output is correct
7 Correct 39 ms 29976 KB Output is correct
8 Correct 49 ms 29952 KB Output is correct
9 Correct 79 ms 39364 KB Output is correct
10 Correct 79 ms 39252 KB Output is correct
11 Correct 78 ms 39448 KB Output is correct
12 Correct 86 ms 39460 KB Output is correct
13 Correct 74 ms 38484 KB Output is correct
14 Correct 84 ms 40276 KB Output is correct
15 Correct 79 ms 40048 KB Output is correct
16 Correct 93 ms 41324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1065 ms 88068 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29528 KB Output is correct
2 Correct 9 ms 29532 KB Output is correct
3 Correct 8 ms 29376 KB Output is correct
4 Correct 9 ms 29532 KB Output is correct
5 Correct 7 ms 29020 KB Output is correct
6 Correct 7 ms 29020 KB Output is correct
7 Correct 9 ms 29396 KB Output is correct
8 Correct 11 ms 29532 KB Output is correct
9 Correct 9 ms 29532 KB Output is correct
10 Correct 9 ms 29532 KB Output is correct
11 Correct 10 ms 29660 KB Output is correct
12 Correct 10 ms 29532 KB Output is correct
13 Correct 7 ms 29276 KB Output is correct
14 Correct 7 ms 29272 KB Output is correct
15 Correct 7 ms 29528 KB Output is correct
16 Correct 8 ms 29532 KB Output is correct
17 Correct 9 ms 29532 KB Output is correct
18 Correct 9 ms 29532 KB Output is correct
19 Correct 8 ms 29532 KB Output is correct
20 Correct 8 ms 29400 KB Output is correct
21 Correct 96 ms 39252 KB Output is correct
22 Correct 82 ms 39760 KB Output is correct
23 Correct 88 ms 39756 KB Output is correct
24 Correct 96 ms 39636 KB Output is correct
25 Correct 104 ms 40460 KB Output is correct
26 Correct 84 ms 40512 KB Output is correct
27 Correct 39 ms 29976 KB Output is correct
28 Correct 49 ms 29952 KB Output is correct
29 Correct 79 ms 39364 KB Output is correct
30 Correct 79 ms 39252 KB Output is correct
31 Correct 78 ms 39448 KB Output is correct
32 Correct 86 ms 39460 KB Output is correct
33 Correct 74 ms 38484 KB Output is correct
34 Correct 84 ms 40276 KB Output is correct
35 Correct 79 ms 40048 KB Output is correct
36 Correct 93 ms 41324 KB Output is correct
37 Correct 189 ms 43408 KB Output is correct
38 Correct 162 ms 45784 KB Output is correct
39 Correct 29 ms 29912 KB Output is correct
40 Correct 43 ms 29976 KB Output is correct
41 Correct 201 ms 45944 KB Output is correct
42 Correct 198 ms 46264 KB Output is correct
43 Correct 195 ms 45808 KB Output is correct
44 Correct 182 ms 45636 KB Output is correct
45 Correct 197 ms 46256 KB Output is correct
46 Correct 192 ms 45888 KB Output is correct
47 Correct 68 ms 37072 KB Output is correct
48 Correct 122 ms 45416 KB Output is correct
49 Correct 139 ms 41908 KB Output is correct
50 Correct 141 ms 44632 KB Output is correct
51 Correct 174 ms 46156 KB Output is correct
52 Correct 188 ms 46360 KB Output is correct
53 Correct 67 ms 39872 KB Output is correct
54 Correct 84 ms 41240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 275 ms 46520 KB Output is correct
2 Correct 272 ms 48316 KB Output is correct
3 Correct 280 ms 49508 KB Output is correct
4 Correct 194 ms 46528 KB Output is correct
5 Correct 258 ms 48212 KB Output is correct
6 Correct 280 ms 50272 KB Output is correct
7 Correct 62 ms 31120 KB Output is correct
8 Correct 67 ms 30928 KB Output is correct
9 Correct 93 ms 38788 KB Output is correct
10 Correct 102 ms 45452 KB Output is correct
11 Correct 152 ms 50256 KB Output is correct
12 Correct 153 ms 50296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29528 KB Output is correct
2 Correct 9 ms 29532 KB Output is correct
3 Correct 8 ms 29376 KB Output is correct
4 Correct 9 ms 29532 KB Output is correct
5 Correct 7 ms 29020 KB Output is correct
6 Correct 7 ms 29020 KB Output is correct
7 Correct 9 ms 29396 KB Output is correct
8 Correct 11 ms 29532 KB Output is correct
9 Correct 9 ms 29532 KB Output is correct
10 Correct 9 ms 29532 KB Output is correct
11 Correct 10 ms 29660 KB Output is correct
12 Correct 10 ms 29532 KB Output is correct
13 Correct 7 ms 29276 KB Output is correct
14 Correct 7 ms 29272 KB Output is correct
15 Correct 7 ms 29528 KB Output is correct
16 Correct 8 ms 29532 KB Output is correct
17 Correct 9 ms 29532 KB Output is correct
18 Correct 9 ms 29532 KB Output is correct
19 Correct 8 ms 29532 KB Output is correct
20 Correct 8 ms 29400 KB Output is correct
21 Correct 9 ms 29532 KB Output is correct
22 Correct 9 ms 29592 KB Output is correct
23 Correct 9 ms 29632 KB Output is correct
24 Correct 9 ms 29532 KB Output is correct
25 Correct 7 ms 29268 KB Output is correct
26 Correct 7 ms 29020 KB Output is correct
27 Correct 10 ms 29528 KB Output is correct
28 Correct 9 ms 29528 KB Output is correct
29 Correct 9 ms 29532 KB Output is correct
30 Correct 9 ms 29532 KB Output is correct
31 Correct 9 ms 29532 KB Output is correct
32 Correct 9 ms 29532 KB Output is correct
33 Correct 7 ms 29276 KB Output is correct
34 Correct 8 ms 29388 KB Output is correct
35 Correct 8 ms 29532 KB Output is correct
36 Correct 9 ms 29532 KB Output is correct
37 Correct 8 ms 29784 KB Output is correct
38 Correct 8 ms 29532 KB Output is correct
39 Correct 96 ms 39252 KB Output is correct
40 Correct 82 ms 39760 KB Output is correct
41 Correct 88 ms 39756 KB Output is correct
42 Correct 96 ms 39636 KB Output is correct
43 Correct 104 ms 40460 KB Output is correct
44 Correct 84 ms 40512 KB Output is correct
45 Correct 39 ms 29976 KB Output is correct
46 Correct 49 ms 29952 KB Output is correct
47 Correct 79 ms 39364 KB Output is correct
48 Correct 79 ms 39252 KB Output is correct
49 Correct 78 ms 39448 KB Output is correct
50 Correct 86 ms 39460 KB Output is correct
51 Correct 74 ms 38484 KB Output is correct
52 Correct 84 ms 40276 KB Output is correct
53 Correct 79 ms 40048 KB Output is correct
54 Correct 93 ms 41324 KB Output is correct
55 Correct 189 ms 43408 KB Output is correct
56 Correct 162 ms 45784 KB Output is correct
57 Correct 29 ms 29912 KB Output is correct
58 Correct 43 ms 29976 KB Output is correct
59 Correct 201 ms 45944 KB Output is correct
60 Correct 198 ms 46264 KB Output is correct
61 Correct 195 ms 45808 KB Output is correct
62 Correct 182 ms 45636 KB Output is correct
63 Correct 197 ms 46256 KB Output is correct
64 Correct 192 ms 45888 KB Output is correct
65 Correct 68 ms 37072 KB Output is correct
66 Correct 122 ms 45416 KB Output is correct
67 Correct 139 ms 41908 KB Output is correct
68 Correct 141 ms 44632 KB Output is correct
69 Correct 174 ms 46156 KB Output is correct
70 Correct 188 ms 46360 KB Output is correct
71 Correct 67 ms 39872 KB Output is correct
72 Correct 84 ms 41240 KB Output is correct
73 Correct 275 ms 46520 KB Output is correct
74 Correct 272 ms 48316 KB Output is correct
75 Correct 280 ms 49508 KB Output is correct
76 Correct 194 ms 46528 KB Output is correct
77 Correct 258 ms 48212 KB Output is correct
78 Correct 280 ms 50272 KB Output is correct
79 Correct 62 ms 31120 KB Output is correct
80 Correct 67 ms 30928 KB Output is correct
81 Correct 93 ms 38788 KB Output is correct
82 Correct 102 ms 45452 KB Output is correct
83 Correct 152 ms 50256 KB Output is correct
84 Correct 153 ms 50296 KB Output is correct
85 Correct 185 ms 44180 KB Output is correct
86 Correct 213 ms 46416 KB Output is correct
87 Correct 184 ms 48260 KB Output is correct
88 Correct 205 ms 50244 KB Output is correct
89 Correct 120 ms 43068 KB Output is correct
90 Correct 213 ms 47384 KB Output is correct
91 Correct 143 ms 44012 KB Output is correct
92 Correct 141 ms 43524 KB Output is correct
93 Correct 190 ms 47428 KB Output is correct
94 Correct 190 ms 47428 KB Output is correct
95 Correct 186 ms 46692 KB Output is correct
96 Correct 190 ms 47424 KB Output is correct
97 Correct 186 ms 47396 KB Output is correct
98 Correct 158 ms 44872 KB Output is correct
99 Correct 71 ms 38352 KB Output is correct
100 Correct 103 ms 44040 KB Output is correct
101 Correct 125 ms 46736 KB Output is correct
102 Correct 129 ms 44340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29528 KB Output is correct
2 Correct 9 ms 29532 KB Output is correct
3 Correct 8 ms 29376 KB Output is correct
4 Correct 9 ms 29532 KB Output is correct
5 Correct 7 ms 29020 KB Output is correct
6 Correct 7 ms 29020 KB Output is correct
7 Correct 9 ms 29396 KB Output is correct
8 Correct 11 ms 29532 KB Output is correct
9 Correct 9 ms 29532 KB Output is correct
10 Correct 9 ms 29532 KB Output is correct
11 Correct 10 ms 29660 KB Output is correct
12 Correct 10 ms 29532 KB Output is correct
13 Correct 7 ms 29276 KB Output is correct
14 Correct 7 ms 29272 KB Output is correct
15 Correct 7 ms 29528 KB Output is correct
16 Correct 8 ms 29532 KB Output is correct
17 Correct 9 ms 29532 KB Output is correct
18 Correct 9 ms 29532 KB Output is correct
19 Correct 8 ms 29532 KB Output is correct
20 Correct 8 ms 29400 KB Output is correct
21 Correct 9 ms 29532 KB Output is correct
22 Correct 9 ms 29592 KB Output is correct
23 Correct 9 ms 29632 KB Output is correct
24 Correct 9 ms 29532 KB Output is correct
25 Correct 7 ms 29268 KB Output is correct
26 Correct 7 ms 29020 KB Output is correct
27 Correct 10 ms 29528 KB Output is correct
28 Correct 9 ms 29528 KB Output is correct
29 Correct 9 ms 29532 KB Output is correct
30 Correct 9 ms 29532 KB Output is correct
31 Correct 9 ms 29532 KB Output is correct
32 Correct 9 ms 29532 KB Output is correct
33 Correct 7 ms 29276 KB Output is correct
34 Correct 8 ms 29388 KB Output is correct
35 Correct 8 ms 29532 KB Output is correct
36 Correct 9 ms 29532 KB Output is correct
37 Correct 8 ms 29784 KB Output is correct
38 Correct 8 ms 29532 KB Output is correct
39 Correct 96 ms 39252 KB Output is correct
40 Correct 82 ms 39760 KB Output is correct
41 Correct 88 ms 39756 KB Output is correct
42 Correct 96 ms 39636 KB Output is correct
43 Correct 104 ms 40460 KB Output is correct
44 Correct 84 ms 40512 KB Output is correct
45 Correct 39 ms 29976 KB Output is correct
46 Correct 49 ms 29952 KB Output is correct
47 Correct 79 ms 39364 KB Output is correct
48 Correct 79 ms 39252 KB Output is correct
49 Correct 78 ms 39448 KB Output is correct
50 Correct 86 ms 39460 KB Output is correct
51 Correct 74 ms 38484 KB Output is correct
52 Correct 84 ms 40276 KB Output is correct
53 Correct 79 ms 40048 KB Output is correct
54 Correct 93 ms 41324 KB Output is correct
55 Execution timed out 1065 ms 88068 KB Time limit exceeded
56 Halted 0 ms 0 KB -