Submission #794913

# Submission time Handle Problem Language Result Execution time Memory
794913 2023-07-27T03:45:32 Z RushB Food Court (JOI21_foodcourt) C++17
68 / 100
1000 ms 76400 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 
const int64_t INF = 1ll << 60;
const int N = 3e5;
const int LG = 20;
long long B[N], K[N], mn[N << 2], delta[N << 2];
vector<int> V[4 * N], GET[N];
short t[N];
int L[N], R[N], C[N], A[N], n, m, q, ans[N];

struct fenw {
        long long bit[N];
        void add(int r, int d) {
                r++;
                for (; r < N; r += r & -r)
                        bit[r] += d;
        }
        long long get(int r) {
                r++;
                long long re = 0;
                for (; r; r &= (r - 1)) 
                        re += bit[r];
                return re;
        }
        int find(long long x) {
                int pos = 0;
                for (int i = LG; i >= 0; i--) {
                        if (pos + (1 << i) < N && bit[pos + (1 << i)] < x) {
                                pos += 1 << i;
                                x -= bit[pos];
                        }
                }
                return pos;
        }
} pos, all;

void add_query(int v, int l, int r, int L, int R, int query_ind) {
        if (R <= l || r <= L) return;
        if (L <= l && r <= R) {
                V[v].push_back(query_ind);
                return;
        }
        int m = l + r >> 1;
        add_query(v << 1, l, m, L, R, query_ind);
        add_query(v << 1 | 1, m, r, L, R, query_ind);
}

void add(int v, int l, int r, int L, int R, int d) {
        if (L <= l && r <= R) {
                mn[v] += d;
                delta[v] += d;
                return;
        }
        int m = l + r >> 1;
        if (R <= m)
                add(v << 1, l, m, L, R, d);
        else if (L >= m)
                add(v << 1 | 1, m, r, L, R, d);
        else {
                add(v << 1, l, m, L, R, d);
                add(v << 1 | 1, m, r, L, R, d);
        }
        mn[v] = min(mn[v << 1], mn[v << 1 | 1]) + delta[v];
}
ll get(int v, int l, int r, int L, int R) {
        if (R <= l || r <= L) return INF;
        if (L <= l && r <= R) return mn[v];
        int m = l + r >> 1;
        return min(get(v << 1, l, m, L, R), get(v << 1 | 1, m, r, L, R)) + delta[v];
}

void solve(int v, int l, int r) {
        for (auto i: V[v]) {
                if (t[i] == 1) {
                        pos.add(i, K[i]);
                        all.add(i, K[i]);
                        add(1, 0, q, i, q, K[i]);
                }
                else {
                        all.add(i, -K[i]);
                        add(1, 0, q, i, q, -K[i]);
                }
        }
        if (l + 1 == r) {
                for (auto i: GET[l]) {
                        ll all_pos = pos.get(i), mn = get(1, 0, q, 0, i + 1), sz = all.get(i) - (mn < 0 ? mn : 0), b = B[i];
                        b += all_pos - sz;
                        ans[i] = (b <= all_pos ? pos.find(b) : N);
                }
        }
        else {
                int m = l + r >> 1;
                solve(v << 1, l, m);
                solve(v << 1 | 1, m, r);
        }
        for (auto i: V[v]) {
                if (t[i] == 1) {
                        pos.add(i, -K[i]);
                        all.add(i, -K[i]);
                        add(1, 0, q, i, q, -K[i]);
                }
                else {
                        all.add(i, +K[i]);
                        add(1, 0, q, i, q, +K[i]);
                }
        }
}

signed main() {
        ios::sync_with_stdio(0), cin.tie(0);
        cin >> n >> m >> q;
        FOR(i, 0, q) {
                cin >> t[i];
                if (t[i] == 1) {
                        cin >> L[i] >> R[i] >> C[i] >> K[i];
                        L[i]--;
                        add_query(1, 0, n, L[i], R[i], i);
                        R[i]--;
                }
                else if (t[i] == 2) {
                        cin >> L[i] >> R[i] >> K[i];
                        L[i]--;
                        add_query(1, 0, n, L[i], R[i], i);
                        R[i]--;
                }
                else {
                        cin >> A[i] >> B[i];
                        A[i]--;
                        GET[A[i]].push_back(i);
                }
        }
        solve(1, 0, n);
        FOR(i, 0, q) if (t[i] == 3)
               cout << (ans[i] == N ? 0 : C[ans[i]]) << '\n'; 
}
//06:22:05

Compilation message

foodcourt.cpp: In function 'void add_query(int, int, int, int, int, int)':
foodcourt.cpp:45:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |         int m = l + r >> 1;
      |                 ~~^~~
foodcourt.cpp: In function 'void add(int, int, int, int, int, int)':
foodcourt.cpp:56:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |         int m = l + r >> 1;
      |                 ~~^~~
foodcourt.cpp: In function 'll get(int, int, int, int, int)':
foodcourt.cpp:70:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   70 |         int m = l + r >> 1;
      |                 ~~^~~
foodcourt.cpp: In function 'void solve(int, int, int)':
foodcourt.cpp:94:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   94 |                 int m = l + r >> 1;
      |                         ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 35924 KB Output is correct
2 Correct 23 ms 36000 KB Output is correct
3 Correct 20 ms 35904 KB Output is correct
4 Correct 23 ms 35996 KB Output is correct
5 Correct 21 ms 35788 KB Output is correct
6 Correct 18 ms 35852 KB Output is correct
7 Correct 22 ms 35924 KB Output is correct
8 Correct 21 ms 35968 KB Output is correct
9 Correct 22 ms 35924 KB Output is correct
10 Correct 25 ms 35948 KB Output is correct
11 Correct 23 ms 35924 KB Output is correct
12 Correct 23 ms 35924 KB Output is correct
13 Correct 18 ms 35796 KB Output is correct
14 Correct 18 ms 35776 KB Output is correct
15 Correct 22 ms 35912 KB Output is correct
16 Correct 24 ms 35972 KB Output is correct
17 Correct 21 ms 35856 KB Output is correct
18 Correct 23 ms 35996 KB Output is correct
19 Correct 19 ms 35904 KB Output is correct
20 Correct 24 ms 35932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 35924 KB Output is correct
2 Correct 23 ms 36000 KB Output is correct
3 Correct 20 ms 35904 KB Output is correct
4 Correct 23 ms 35996 KB Output is correct
5 Correct 21 ms 35788 KB Output is correct
6 Correct 18 ms 35852 KB Output is correct
7 Correct 22 ms 35924 KB Output is correct
8 Correct 21 ms 35968 KB Output is correct
9 Correct 22 ms 35924 KB Output is correct
10 Correct 25 ms 35948 KB Output is correct
11 Correct 23 ms 35924 KB Output is correct
12 Correct 23 ms 35924 KB Output is correct
13 Correct 18 ms 35796 KB Output is correct
14 Correct 18 ms 35776 KB Output is correct
15 Correct 22 ms 35912 KB Output is correct
16 Correct 24 ms 35972 KB Output is correct
17 Correct 21 ms 35856 KB Output is correct
18 Correct 23 ms 35996 KB Output is correct
19 Correct 19 ms 35904 KB Output is correct
20 Correct 24 ms 35932 KB Output is correct
21 Correct 22 ms 35916 KB Output is correct
22 Correct 22 ms 36000 KB Output is correct
23 Correct 21 ms 35956 KB Output is correct
24 Correct 22 ms 36008 KB Output is correct
25 Correct 18 ms 35784 KB Output is correct
26 Correct 20 ms 35796 KB Output is correct
27 Correct 23 ms 35868 KB Output is correct
28 Correct 23 ms 36004 KB Output is correct
29 Correct 23 ms 35988 KB Output is correct
30 Correct 23 ms 35888 KB Output is correct
31 Correct 22 ms 35912 KB Output is correct
32 Correct 23 ms 36048 KB Output is correct
33 Correct 20 ms 35788 KB Output is correct
34 Correct 19 ms 35796 KB Output is correct
35 Correct 23 ms 35924 KB Output is correct
36 Correct 28 ms 35984 KB Output is correct
37 Correct 20 ms 35840 KB Output is correct
38 Correct 20 ms 35924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 191 ms 45412 KB Output is correct
2 Correct 179 ms 44980 KB Output is correct
3 Correct 198 ms 45560 KB Output is correct
4 Correct 196 ms 45516 KB Output is correct
5 Correct 205 ms 45240 KB Output is correct
6 Correct 195 ms 45224 KB Output is correct
7 Correct 48 ms 41312 KB Output is correct
8 Correct 50 ms 41396 KB Output is correct
9 Correct 216 ms 45368 KB Output is correct
10 Correct 249 ms 45700 KB Output is correct
11 Correct 213 ms 45508 KB Output is correct
12 Correct 243 ms 45616 KB Output is correct
13 Correct 136 ms 43656 KB Output is correct
14 Correct 141 ms 44620 KB Output is correct
15 Correct 119 ms 43496 KB Output is correct
16 Correct 117 ms 44016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 76400 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 35924 KB Output is correct
2 Correct 23 ms 36000 KB Output is correct
3 Correct 20 ms 35904 KB Output is correct
4 Correct 23 ms 35996 KB Output is correct
5 Correct 21 ms 35788 KB Output is correct
6 Correct 18 ms 35852 KB Output is correct
7 Correct 22 ms 35924 KB Output is correct
8 Correct 21 ms 35968 KB Output is correct
9 Correct 22 ms 35924 KB Output is correct
10 Correct 25 ms 35948 KB Output is correct
11 Correct 23 ms 35924 KB Output is correct
12 Correct 23 ms 35924 KB Output is correct
13 Correct 18 ms 35796 KB Output is correct
14 Correct 18 ms 35776 KB Output is correct
15 Correct 22 ms 35912 KB Output is correct
16 Correct 24 ms 35972 KB Output is correct
17 Correct 21 ms 35856 KB Output is correct
18 Correct 23 ms 35996 KB Output is correct
19 Correct 19 ms 35904 KB Output is correct
20 Correct 24 ms 35932 KB Output is correct
21 Correct 191 ms 45412 KB Output is correct
22 Correct 179 ms 44980 KB Output is correct
23 Correct 198 ms 45560 KB Output is correct
24 Correct 196 ms 45516 KB Output is correct
25 Correct 205 ms 45240 KB Output is correct
26 Correct 195 ms 45224 KB Output is correct
27 Correct 48 ms 41312 KB Output is correct
28 Correct 50 ms 41396 KB Output is correct
29 Correct 216 ms 45368 KB Output is correct
30 Correct 249 ms 45700 KB Output is correct
31 Correct 213 ms 45508 KB Output is correct
32 Correct 243 ms 45616 KB Output is correct
33 Correct 136 ms 43656 KB Output is correct
34 Correct 141 ms 44620 KB Output is correct
35 Correct 119 ms 43496 KB Output is correct
36 Correct 117 ms 44016 KB Output is correct
37 Correct 284 ms 45664 KB Output is correct
38 Correct 257 ms 45140 KB Output is correct
39 Correct 43 ms 40956 KB Output is correct
40 Correct 57 ms 41364 KB Output is correct
41 Correct 331 ms 46496 KB Output is correct
42 Correct 325 ms 46928 KB Output is correct
43 Correct 336 ms 46928 KB Output is correct
44 Correct 357 ms 46728 KB Output is correct
45 Correct 342 ms 47016 KB Output is correct
46 Correct 329 ms 46924 KB Output is correct
47 Correct 59 ms 41976 KB Output is correct
48 Correct 345 ms 46332 KB Output is correct
49 Correct 236 ms 44256 KB Output is correct
50 Correct 294 ms 45840 KB Output is correct
51 Correct 409 ms 47092 KB Output is correct
52 Correct 346 ms 47112 KB Output is correct
53 Correct 117 ms 42720 KB Output is correct
54 Correct 119 ms 44132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 214 ms 45128 KB Output is correct
2 Correct 242 ms 45516 KB Output is correct
3 Correct 256 ms 45836 KB Output is correct
4 Correct 179 ms 43724 KB Output is correct
5 Correct 218 ms 44936 KB Output is correct
6 Correct 249 ms 45936 KB Output is correct
7 Correct 49 ms 41280 KB Output is correct
8 Correct 49 ms 40956 KB Output is correct
9 Correct 60 ms 42192 KB Output is correct
10 Correct 192 ms 42836 KB Output is correct
11 Correct 275 ms 45028 KB Output is correct
12 Correct 290 ms 45132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 35924 KB Output is correct
2 Correct 23 ms 36000 KB Output is correct
3 Correct 20 ms 35904 KB Output is correct
4 Correct 23 ms 35996 KB Output is correct
5 Correct 21 ms 35788 KB Output is correct
6 Correct 18 ms 35852 KB Output is correct
7 Correct 22 ms 35924 KB Output is correct
8 Correct 21 ms 35968 KB Output is correct
9 Correct 22 ms 35924 KB Output is correct
10 Correct 25 ms 35948 KB Output is correct
11 Correct 23 ms 35924 KB Output is correct
12 Correct 23 ms 35924 KB Output is correct
13 Correct 18 ms 35796 KB Output is correct
14 Correct 18 ms 35776 KB Output is correct
15 Correct 22 ms 35912 KB Output is correct
16 Correct 24 ms 35972 KB Output is correct
17 Correct 21 ms 35856 KB Output is correct
18 Correct 23 ms 35996 KB Output is correct
19 Correct 19 ms 35904 KB Output is correct
20 Correct 24 ms 35932 KB Output is correct
21 Correct 22 ms 35916 KB Output is correct
22 Correct 22 ms 36000 KB Output is correct
23 Correct 21 ms 35956 KB Output is correct
24 Correct 22 ms 36008 KB Output is correct
25 Correct 18 ms 35784 KB Output is correct
26 Correct 20 ms 35796 KB Output is correct
27 Correct 23 ms 35868 KB Output is correct
28 Correct 23 ms 36004 KB Output is correct
29 Correct 23 ms 35988 KB Output is correct
30 Correct 23 ms 35888 KB Output is correct
31 Correct 22 ms 35912 KB Output is correct
32 Correct 23 ms 36048 KB Output is correct
33 Correct 20 ms 35788 KB Output is correct
34 Correct 19 ms 35796 KB Output is correct
35 Correct 23 ms 35924 KB Output is correct
36 Correct 28 ms 35984 KB Output is correct
37 Correct 20 ms 35840 KB Output is correct
38 Correct 20 ms 35924 KB Output is correct
39 Correct 191 ms 45412 KB Output is correct
40 Correct 179 ms 44980 KB Output is correct
41 Correct 198 ms 45560 KB Output is correct
42 Correct 196 ms 45516 KB Output is correct
43 Correct 205 ms 45240 KB Output is correct
44 Correct 195 ms 45224 KB Output is correct
45 Correct 48 ms 41312 KB Output is correct
46 Correct 50 ms 41396 KB Output is correct
47 Correct 216 ms 45368 KB Output is correct
48 Correct 249 ms 45700 KB Output is correct
49 Correct 213 ms 45508 KB Output is correct
50 Correct 243 ms 45616 KB Output is correct
51 Correct 136 ms 43656 KB Output is correct
52 Correct 141 ms 44620 KB Output is correct
53 Correct 119 ms 43496 KB Output is correct
54 Correct 117 ms 44016 KB Output is correct
55 Correct 284 ms 45664 KB Output is correct
56 Correct 257 ms 45140 KB Output is correct
57 Correct 43 ms 40956 KB Output is correct
58 Correct 57 ms 41364 KB Output is correct
59 Correct 331 ms 46496 KB Output is correct
60 Correct 325 ms 46928 KB Output is correct
61 Correct 336 ms 46928 KB Output is correct
62 Correct 357 ms 46728 KB Output is correct
63 Correct 342 ms 47016 KB Output is correct
64 Correct 329 ms 46924 KB Output is correct
65 Correct 59 ms 41976 KB Output is correct
66 Correct 345 ms 46332 KB Output is correct
67 Correct 236 ms 44256 KB Output is correct
68 Correct 294 ms 45840 KB Output is correct
69 Correct 409 ms 47092 KB Output is correct
70 Correct 346 ms 47112 KB Output is correct
71 Correct 117 ms 42720 KB Output is correct
72 Correct 119 ms 44132 KB Output is correct
73 Correct 214 ms 45128 KB Output is correct
74 Correct 242 ms 45516 KB Output is correct
75 Correct 256 ms 45836 KB Output is correct
76 Correct 179 ms 43724 KB Output is correct
77 Correct 218 ms 44936 KB Output is correct
78 Correct 249 ms 45936 KB Output is correct
79 Correct 49 ms 41280 KB Output is correct
80 Correct 49 ms 40956 KB Output is correct
81 Correct 60 ms 42192 KB Output is correct
82 Correct 192 ms 42836 KB Output is correct
83 Correct 275 ms 45028 KB Output is correct
84 Correct 290 ms 45132 KB Output is correct
85 Correct 266 ms 45588 KB Output is correct
86 Correct 298 ms 46612 KB Output is correct
87 Correct 294 ms 45828 KB Output is correct
88 Correct 342 ms 46912 KB Output is correct
89 Correct 217 ms 43752 KB Output is correct
90 Correct 360 ms 46996 KB Output is correct
91 Correct 283 ms 45208 KB Output is correct
92 Correct 249 ms 44716 KB Output is correct
93 Correct 328 ms 46956 KB Output is correct
94 Correct 356 ms 46740 KB Output is correct
95 Correct 314 ms 46636 KB Output is correct
96 Correct 351 ms 46948 KB Output is correct
97 Correct 330 ms 46960 KB Output is correct
98 Correct 280 ms 45512 KB Output is correct
99 Correct 58 ms 41928 KB Output is correct
100 Correct 285 ms 44780 KB Output is correct
101 Correct 348 ms 46228 KB Output is correct
102 Correct 191 ms 44876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 35924 KB Output is correct
2 Correct 23 ms 36000 KB Output is correct
3 Correct 20 ms 35904 KB Output is correct
4 Correct 23 ms 35996 KB Output is correct
5 Correct 21 ms 35788 KB Output is correct
6 Correct 18 ms 35852 KB Output is correct
7 Correct 22 ms 35924 KB Output is correct
8 Correct 21 ms 35968 KB Output is correct
9 Correct 22 ms 35924 KB Output is correct
10 Correct 25 ms 35948 KB Output is correct
11 Correct 23 ms 35924 KB Output is correct
12 Correct 23 ms 35924 KB Output is correct
13 Correct 18 ms 35796 KB Output is correct
14 Correct 18 ms 35776 KB Output is correct
15 Correct 22 ms 35912 KB Output is correct
16 Correct 24 ms 35972 KB Output is correct
17 Correct 21 ms 35856 KB Output is correct
18 Correct 23 ms 35996 KB Output is correct
19 Correct 19 ms 35904 KB Output is correct
20 Correct 24 ms 35932 KB Output is correct
21 Correct 22 ms 35916 KB Output is correct
22 Correct 22 ms 36000 KB Output is correct
23 Correct 21 ms 35956 KB Output is correct
24 Correct 22 ms 36008 KB Output is correct
25 Correct 18 ms 35784 KB Output is correct
26 Correct 20 ms 35796 KB Output is correct
27 Correct 23 ms 35868 KB Output is correct
28 Correct 23 ms 36004 KB Output is correct
29 Correct 23 ms 35988 KB Output is correct
30 Correct 23 ms 35888 KB Output is correct
31 Correct 22 ms 35912 KB Output is correct
32 Correct 23 ms 36048 KB Output is correct
33 Correct 20 ms 35788 KB Output is correct
34 Correct 19 ms 35796 KB Output is correct
35 Correct 23 ms 35924 KB Output is correct
36 Correct 28 ms 35984 KB Output is correct
37 Correct 20 ms 35840 KB Output is correct
38 Correct 20 ms 35924 KB Output is correct
39 Correct 191 ms 45412 KB Output is correct
40 Correct 179 ms 44980 KB Output is correct
41 Correct 198 ms 45560 KB Output is correct
42 Correct 196 ms 45516 KB Output is correct
43 Correct 205 ms 45240 KB Output is correct
44 Correct 195 ms 45224 KB Output is correct
45 Correct 48 ms 41312 KB Output is correct
46 Correct 50 ms 41396 KB Output is correct
47 Correct 216 ms 45368 KB Output is correct
48 Correct 249 ms 45700 KB Output is correct
49 Correct 213 ms 45508 KB Output is correct
50 Correct 243 ms 45616 KB Output is correct
51 Correct 136 ms 43656 KB Output is correct
52 Correct 141 ms 44620 KB Output is correct
53 Correct 119 ms 43496 KB Output is correct
54 Correct 117 ms 44016 KB Output is correct
55 Execution timed out 1075 ms 76400 KB Time limit exceeded
56 Halted 0 ms 0 KB -