답안 #891624

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

using namespace std;

struct update {
    int c, k;
};


const int MAX_N = 2.5e5;
const int MAX_Q = 2.5e5;
int ans[MAX_Q + 1];
update updates[MAX_Q + 2];
long long queries[MAX_Q + 1];
vector<int> updatesByPos[MAX_N + 1], queriesByPos[MAX_N + 1];

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];

    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 k ) {
        propag( v, l, r );

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

        if ( lu <= l && r <= ru ) {
            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 );
        update( v * 2 + 2, mid + 1, r, lu, ru, k );
    }

    long long query( int v, int l, int r, int p ) {
        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;

struct AIB {
    long long aib[MAX_Q + 1];

    void update( int i, int x ) {
        while ( i <= MAX_Q ) {
            aib[i] += x;
            i += (i & -i);
        }
    }

    int firstHigherOrEqual( long long x ) {
        int pos = 0;
        for ( int p = log2( MAX_Q ); p >= 0; p-- ) {
            if ( pos + (1 << p) <= MAX_Q && x - aib[pos + (1 << p)] > 0 ) {
                pos += (1 << p);
                x -= aib[pos];
            }
        }

        return pos + 1;
    }
} us;

signed main() {
    ios_base::sync_with_stdio( false );
    cin.tie( NULL );
    cout.tie( NULL );

    int n, m, q;

    cin >> n >> m >> q;
    for ( int t = 1; 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 );
            updates[t] = { c, k };
            updatesByPos[l].push_back( t );
            updatesByPos[r + 1].push_back( -t );
        } 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;
            x += qs.query( 0, 1, n, p );
            queries[t] = x;
            queriesByPos[p].push_back( t );
        }
    }

    for ( int t = 1; t <= q; t++ )
        ans[t] = -1;

    for ( int i = 1; i <= n; i++ ) {
        for ( int t: updatesByPos[i] ) {
            if ( t > 0 )
                us.update( t, updates[t].k );
            else
                us.update( -t, -updates[-t].k );
        }

        for ( int t: queriesByPos[i] ) {
            int j = us.firstHigherOrEqual( queries[t] );
            ans[t] = (j > t ? 0 :updates[j].c );
        }
    }

    for ( int t = 1; t <= q; t++ ) {
        if ( ans[t] != -1 )
            cout << ans[t] << "\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 16984 KB Output is correct
2 Correct 5 ms 16988 KB Output is correct
3 Correct 5 ms 16988 KB Output is correct
4 Correct 5 ms 16888 KB Output is correct
5 Correct 4 ms 16732 KB Output is correct
6 Correct 3 ms 16884 KB Output is correct
7 Correct 5 ms 17076 KB Output is correct
8 Correct 5 ms 16888 KB Output is correct
9 Correct 5 ms 16984 KB Output is correct
10 Correct 5 ms 16984 KB Output is correct
11 Correct 5 ms 16988 KB Output is correct
12 Correct 4 ms 16988 KB Output is correct
13 Correct 4 ms 16988 KB Output is correct
14 Correct 4 ms 16988 KB Output is correct
15 Correct 4 ms 16988 KB Output is correct
16 Correct 5 ms 17032 KB Output is correct
17 Correct 5 ms 16988 KB Output is correct
18 Correct 5 ms 16988 KB Output is correct
19 Correct 4 ms 16896 KB Output is correct
20 Correct 5 ms 16988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 16984 KB Output is correct
2 Correct 5 ms 16988 KB Output is correct
3 Correct 5 ms 16988 KB Output is correct
4 Correct 5 ms 16888 KB Output is correct
5 Correct 4 ms 16732 KB Output is correct
6 Correct 3 ms 16884 KB Output is correct
7 Correct 5 ms 17076 KB Output is correct
8 Correct 5 ms 16888 KB Output is correct
9 Correct 5 ms 16984 KB Output is correct
10 Correct 5 ms 16984 KB Output is correct
11 Correct 5 ms 16988 KB Output is correct
12 Correct 4 ms 16988 KB Output is correct
13 Correct 4 ms 16988 KB Output is correct
14 Correct 4 ms 16988 KB Output is correct
15 Correct 4 ms 16988 KB Output is correct
16 Correct 5 ms 17032 KB Output is correct
17 Correct 5 ms 16988 KB Output is correct
18 Correct 5 ms 16988 KB Output is correct
19 Correct 4 ms 16896 KB Output is correct
20 Correct 5 ms 16988 KB Output is correct
21 Correct 6 ms 16988 KB Output is correct
22 Correct 5 ms 16988 KB Output is correct
23 Correct 5 ms 16988 KB Output is correct
24 Correct 5 ms 17064 KB Output is correct
25 Correct 4 ms 16988 KB Output is correct
26 Correct 4 ms 16732 KB Output is correct
27 Correct 5 ms 16988 KB Output is correct
28 Correct 5 ms 16988 KB Output is correct
29 Correct 5 ms 16884 KB Output is correct
30 Correct 5 ms 16988 KB Output is correct
31 Correct 5 ms 16988 KB Output is correct
32 Correct 6 ms 16988 KB Output is correct
33 Correct 4 ms 16988 KB Output is correct
34 Correct 4 ms 17032 KB Output is correct
35 Correct 4 ms 16988 KB Output is correct
36 Correct 5 ms 16904 KB Output is correct
37 Correct 4 ms 16984 KB Output is correct
38 Correct 4 ms 16988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 23380 KB Output is correct
2 Correct 55 ms 23684 KB Output is correct
3 Correct 54 ms 23380 KB Output is correct
4 Correct 54 ms 23376 KB Output is correct
5 Correct 55 ms 23376 KB Output is correct
6 Correct 59 ms 23376 KB Output is correct
7 Correct 17 ms 18512 KB Output is correct
8 Correct 19 ms 18772 KB Output is correct
9 Correct 55 ms 23228 KB Output is correct
10 Correct 56 ms 23316 KB Output is correct
11 Correct 55 ms 23192 KB Output is correct
12 Correct 55 ms 23380 KB Output is correct
13 Correct 46 ms 22864 KB Output is correct
14 Correct 53 ms 23380 KB Output is correct
15 Correct 62 ms 23420 KB Output is correct
16 Correct 57 ms 23636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 319 ms 42064 KB Output is correct
2 Correct 262 ms 40016 KB Output is correct
3 Correct 346 ms 43936 KB Output is correct
4 Correct 267 ms 41044 KB Output is correct
5 Correct 247 ms 40528 KB Output is correct
6 Correct 360 ms 44716 KB Output is correct
7 Correct 70 ms 24928 KB Output is correct
8 Correct 72 ms 25028 KB Output is correct
9 Runtime error 98 ms 66164 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 16984 KB Output is correct
2 Correct 5 ms 16988 KB Output is correct
3 Correct 5 ms 16988 KB Output is correct
4 Correct 5 ms 16888 KB Output is correct
5 Correct 4 ms 16732 KB Output is correct
6 Correct 3 ms 16884 KB Output is correct
7 Correct 5 ms 17076 KB Output is correct
8 Correct 5 ms 16888 KB Output is correct
9 Correct 5 ms 16984 KB Output is correct
10 Correct 5 ms 16984 KB Output is correct
11 Correct 5 ms 16988 KB Output is correct
12 Correct 4 ms 16988 KB Output is correct
13 Correct 4 ms 16988 KB Output is correct
14 Correct 4 ms 16988 KB Output is correct
15 Correct 4 ms 16988 KB Output is correct
16 Correct 5 ms 17032 KB Output is correct
17 Correct 5 ms 16988 KB Output is correct
18 Correct 5 ms 16988 KB Output is correct
19 Correct 4 ms 16896 KB Output is correct
20 Correct 5 ms 16988 KB Output is correct
21 Correct 54 ms 23380 KB Output is correct
22 Correct 55 ms 23684 KB Output is correct
23 Correct 54 ms 23380 KB Output is correct
24 Correct 54 ms 23376 KB Output is correct
25 Correct 55 ms 23376 KB Output is correct
26 Correct 59 ms 23376 KB Output is correct
27 Correct 17 ms 18512 KB Output is correct
28 Correct 19 ms 18772 KB Output is correct
29 Correct 55 ms 23228 KB Output is correct
30 Correct 56 ms 23316 KB Output is correct
31 Correct 55 ms 23192 KB Output is correct
32 Correct 55 ms 23380 KB Output is correct
33 Correct 46 ms 22864 KB Output is correct
34 Correct 53 ms 23380 KB Output is correct
35 Correct 62 ms 23420 KB Output is correct
36 Correct 57 ms 23636 KB Output is correct
37 Correct 62 ms 22904 KB Output is correct
38 Correct 54 ms 22628 KB Output is correct
39 Correct 15 ms 18264 KB Output is correct
40 Correct 18 ms 18424 KB Output is correct
41 Correct 61 ms 22868 KB Output is correct
42 Correct 64 ms 23252 KB Output is correct
43 Correct 73 ms 23120 KB Output is correct
44 Correct 67 ms 23124 KB Output is correct
45 Correct 87 ms 23072 KB Output is correct
46 Correct 71 ms 23188 KB Output is correct
47 Correct 29 ms 22348 KB Output is correct
48 Correct 61 ms 22356 KB Output is correct
49 Correct 49 ms 22112 KB Output is correct
50 Correct 59 ms 22656 KB Output is correct
51 Correct 75 ms 23124 KB Output is correct
52 Correct 68 ms 23120 KB Output is correct
53 Correct 45 ms 22848 KB Output is correct
54 Correct 56 ms 23636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 23888 KB Output is correct
2 Correct 59 ms 24148 KB Output is correct
3 Correct 62 ms 24404 KB Output is correct
4 Correct 44 ms 23268 KB Output is correct
5 Correct 57 ms 23636 KB Output is correct
6 Correct 61 ms 24324 KB Output is correct
7 Correct 22 ms 19276 KB Output is correct
8 Correct 21 ms 19036 KB Output is correct
9 Correct 35 ms 23388 KB Output is correct
10 Correct 45 ms 22448 KB Output is correct
11 Correct 60 ms 23376 KB Output is correct
12 Correct 56 ms 23348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 16984 KB Output is correct
2 Correct 5 ms 16988 KB Output is correct
3 Correct 5 ms 16988 KB Output is correct
4 Correct 5 ms 16888 KB Output is correct
5 Correct 4 ms 16732 KB Output is correct
6 Correct 3 ms 16884 KB Output is correct
7 Correct 5 ms 17076 KB Output is correct
8 Correct 5 ms 16888 KB Output is correct
9 Correct 5 ms 16984 KB Output is correct
10 Correct 5 ms 16984 KB Output is correct
11 Correct 5 ms 16988 KB Output is correct
12 Correct 4 ms 16988 KB Output is correct
13 Correct 4 ms 16988 KB Output is correct
14 Correct 4 ms 16988 KB Output is correct
15 Correct 4 ms 16988 KB Output is correct
16 Correct 5 ms 17032 KB Output is correct
17 Correct 5 ms 16988 KB Output is correct
18 Correct 5 ms 16988 KB Output is correct
19 Correct 4 ms 16896 KB Output is correct
20 Correct 5 ms 16988 KB Output is correct
21 Correct 6 ms 16988 KB Output is correct
22 Correct 5 ms 16988 KB Output is correct
23 Correct 5 ms 16988 KB Output is correct
24 Correct 5 ms 17064 KB Output is correct
25 Correct 4 ms 16988 KB Output is correct
26 Correct 4 ms 16732 KB Output is correct
27 Correct 5 ms 16988 KB Output is correct
28 Correct 5 ms 16988 KB Output is correct
29 Correct 5 ms 16884 KB Output is correct
30 Correct 5 ms 16988 KB Output is correct
31 Correct 5 ms 16988 KB Output is correct
32 Correct 6 ms 16988 KB Output is correct
33 Correct 4 ms 16988 KB Output is correct
34 Correct 4 ms 17032 KB Output is correct
35 Correct 4 ms 16988 KB Output is correct
36 Correct 5 ms 16904 KB Output is correct
37 Correct 4 ms 16984 KB Output is correct
38 Correct 4 ms 16988 KB Output is correct
39 Correct 54 ms 23380 KB Output is correct
40 Correct 55 ms 23684 KB Output is correct
41 Correct 54 ms 23380 KB Output is correct
42 Correct 54 ms 23376 KB Output is correct
43 Correct 55 ms 23376 KB Output is correct
44 Correct 59 ms 23376 KB Output is correct
45 Correct 17 ms 18512 KB Output is correct
46 Correct 19 ms 18772 KB Output is correct
47 Correct 55 ms 23228 KB Output is correct
48 Correct 56 ms 23316 KB Output is correct
49 Correct 55 ms 23192 KB Output is correct
50 Correct 55 ms 23380 KB Output is correct
51 Correct 46 ms 22864 KB Output is correct
52 Correct 53 ms 23380 KB Output is correct
53 Correct 62 ms 23420 KB Output is correct
54 Correct 57 ms 23636 KB Output is correct
55 Correct 62 ms 22904 KB Output is correct
56 Correct 54 ms 22628 KB Output is correct
57 Correct 15 ms 18264 KB Output is correct
58 Correct 18 ms 18424 KB Output is correct
59 Correct 61 ms 22868 KB Output is correct
60 Correct 64 ms 23252 KB Output is correct
61 Correct 73 ms 23120 KB Output is correct
62 Correct 67 ms 23124 KB Output is correct
63 Correct 87 ms 23072 KB Output is correct
64 Correct 71 ms 23188 KB Output is correct
65 Correct 29 ms 22348 KB Output is correct
66 Correct 61 ms 22356 KB Output is correct
67 Correct 49 ms 22112 KB Output is correct
68 Correct 59 ms 22656 KB Output is correct
69 Correct 75 ms 23124 KB Output is correct
70 Correct 68 ms 23120 KB Output is correct
71 Correct 45 ms 22848 KB Output is correct
72 Correct 56 ms 23636 KB Output is correct
73 Correct 59 ms 23888 KB Output is correct
74 Correct 59 ms 24148 KB Output is correct
75 Correct 62 ms 24404 KB Output is correct
76 Correct 44 ms 23268 KB Output is correct
77 Correct 57 ms 23636 KB Output is correct
78 Correct 61 ms 24324 KB Output is correct
79 Correct 22 ms 19276 KB Output is correct
80 Correct 21 ms 19036 KB Output is correct
81 Correct 35 ms 23388 KB Output is correct
82 Correct 45 ms 22448 KB Output is correct
83 Correct 60 ms 23376 KB Output is correct
84 Correct 56 ms 23348 KB Output is correct
85 Correct 67 ms 23256 KB Output is correct
86 Correct 74 ms 23624 KB Output is correct
87 Correct 61 ms 23464 KB Output is correct
88 Correct 75 ms 23892 KB Output is correct
89 Correct 46 ms 22352 KB Output is correct
90 Correct 78 ms 23552 KB Output is correct
91 Correct 58 ms 22864 KB Output is correct
92 Correct 56 ms 22612 KB Output is correct
93 Correct 74 ms 23640 KB Output is correct
94 Correct 69 ms 23508 KB Output is correct
95 Correct 77 ms 23892 KB Output is correct
96 Correct 73 ms 23580 KB Output is correct
97 Correct 72 ms 23628 KB Output is correct
98 Correct 63 ms 23124 KB Output is correct
99 Correct 33 ms 22860 KB Output is correct
100 Correct 55 ms 22356 KB Output is correct
101 Correct 63 ms 22864 KB Output is correct
102 Correct 56 ms 23652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 16984 KB Output is correct
2 Correct 5 ms 16988 KB Output is correct
3 Correct 5 ms 16988 KB Output is correct
4 Correct 5 ms 16888 KB Output is correct
5 Correct 4 ms 16732 KB Output is correct
6 Correct 3 ms 16884 KB Output is correct
7 Correct 5 ms 17076 KB Output is correct
8 Correct 5 ms 16888 KB Output is correct
9 Correct 5 ms 16984 KB Output is correct
10 Correct 5 ms 16984 KB Output is correct
11 Correct 5 ms 16988 KB Output is correct
12 Correct 4 ms 16988 KB Output is correct
13 Correct 4 ms 16988 KB Output is correct
14 Correct 4 ms 16988 KB Output is correct
15 Correct 4 ms 16988 KB Output is correct
16 Correct 5 ms 17032 KB Output is correct
17 Correct 5 ms 16988 KB Output is correct
18 Correct 5 ms 16988 KB Output is correct
19 Correct 4 ms 16896 KB Output is correct
20 Correct 5 ms 16988 KB Output is correct
21 Correct 6 ms 16988 KB Output is correct
22 Correct 5 ms 16988 KB Output is correct
23 Correct 5 ms 16988 KB Output is correct
24 Correct 5 ms 17064 KB Output is correct
25 Correct 4 ms 16988 KB Output is correct
26 Correct 4 ms 16732 KB Output is correct
27 Correct 5 ms 16988 KB Output is correct
28 Correct 5 ms 16988 KB Output is correct
29 Correct 5 ms 16884 KB Output is correct
30 Correct 5 ms 16988 KB Output is correct
31 Correct 5 ms 16988 KB Output is correct
32 Correct 6 ms 16988 KB Output is correct
33 Correct 4 ms 16988 KB Output is correct
34 Correct 4 ms 17032 KB Output is correct
35 Correct 4 ms 16988 KB Output is correct
36 Correct 5 ms 16904 KB Output is correct
37 Correct 4 ms 16984 KB Output is correct
38 Correct 4 ms 16988 KB Output is correct
39 Correct 54 ms 23380 KB Output is correct
40 Correct 55 ms 23684 KB Output is correct
41 Correct 54 ms 23380 KB Output is correct
42 Correct 54 ms 23376 KB Output is correct
43 Correct 55 ms 23376 KB Output is correct
44 Correct 59 ms 23376 KB Output is correct
45 Correct 17 ms 18512 KB Output is correct
46 Correct 19 ms 18772 KB Output is correct
47 Correct 55 ms 23228 KB Output is correct
48 Correct 56 ms 23316 KB Output is correct
49 Correct 55 ms 23192 KB Output is correct
50 Correct 55 ms 23380 KB Output is correct
51 Correct 46 ms 22864 KB Output is correct
52 Correct 53 ms 23380 KB Output is correct
53 Correct 62 ms 23420 KB Output is correct
54 Correct 57 ms 23636 KB Output is correct
55 Correct 319 ms 42064 KB Output is correct
56 Correct 262 ms 40016 KB Output is correct
57 Correct 346 ms 43936 KB Output is correct
58 Correct 267 ms 41044 KB Output is correct
59 Correct 247 ms 40528 KB Output is correct
60 Correct 360 ms 44716 KB Output is correct
61 Correct 70 ms 24928 KB Output is correct
62 Correct 72 ms 25028 KB Output is correct
63 Runtime error 98 ms 66164 KB Execution killed with signal 11
64 Halted 0 ms 0 KB -