Submission #794921

# Submission time Handle Problem Language Result Execution time Memory
794921 2023-07-27T04:01:38 Z RushB Food Court (JOI21_foodcourt) C++17
68 / 100
1000 ms 117420 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 = 18;
long long B[N], mn[N << 2], delta[N << 2];
vector<array<int, 2>> ad[N << 2], del[N << 2];
vector<array<ll, 2>> GET[N];
short t[N];
int L[N], R[N], C[N], A[N], n, m, q, ans[N], K[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) {
                if (t[query_ind] == 1)
                        ad[v].push_back({query_ind, K[query_ind]});
                else
                        del[v].push_back({query_ind, K[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 (L <= l && r <= R) return mn[v];
        int m = l + r >> 1;
        if (R <= m)
                return get(v << 1, l, m, L, R) + delta[v];
        else if (L >= m)
                return get(v << 1 | 1, m, r, L, R) + delta[v];
        else 
                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, K]: ad[v]) {
                pos.add(i, K);
                all.add(i, K);
                add(1, 0, q, i, q, K);
        }
        for (auto [i, K]: del[v]) {
                all.add(i, -K);
                add(1, 0, q, i, q, -K);
        }
        if (l + 1 == r) {
                for (auto P: GET[l]) {
                        ll b = P[0];
                        int i = P[1];
                        ll all_pos = pos.get(i), mn = get(1, 0, q, 0, i + 1), sz = all.get(i) - (mn < 0 ? mn : 0);
                        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, K]: ad[v]) {
                pos.add(i, -K);
                all.add(i, -K);
                add(1, 0, q, i, q, -K);
        }
        for (auto [i, K]: del[v]) {
                all.add(i, K);
                add(1, 0, q, i, q, K);
        }
}

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({B[i], 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:49:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |         int m = l + r >> 1;
      |                 ~~^~~
foodcourt.cpp: In function 'void add(int, int, int, int, int, int)':
foodcourt.cpp:60:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |         int m = l + r >> 1;
      |                 ~~^~~
foodcourt.cpp: In function 'll get(int, int, int, int, int)':
foodcourt.cpp:73:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   73 |         int m = l + r >> 1;
      |                 ~~^~~
foodcourt.cpp: In function 'void solve(int, int, int)':
foodcourt.cpp:102:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  102 |                 int m = l + r >> 1;
      |                         ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 33 ms 64084 KB Output is correct
2 Correct 37 ms 64240 KB Output is correct
3 Correct 33 ms 64080 KB Output is correct
4 Correct 35 ms 64212 KB Output is correct
5 Correct 31 ms 63932 KB Output is correct
6 Correct 30 ms 63956 KB Output is correct
7 Correct 34 ms 64240 KB Output is correct
8 Correct 34 ms 64188 KB Output is correct
9 Correct 35 ms 64196 KB Output is correct
10 Correct 35 ms 64244 KB Output is correct
11 Correct 38 ms 64256 KB Output is correct
12 Correct 34 ms 64212 KB Output is correct
13 Correct 30 ms 64036 KB Output is correct
14 Correct 30 ms 63972 KB Output is correct
15 Correct 34 ms 64104 KB Output is correct
16 Correct 35 ms 64224 KB Output is correct
17 Correct 38 ms 64076 KB Output is correct
18 Correct 35 ms 64212 KB Output is correct
19 Correct 32 ms 64064 KB Output is correct
20 Correct 32 ms 64048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 64084 KB Output is correct
2 Correct 37 ms 64240 KB Output is correct
3 Correct 33 ms 64080 KB Output is correct
4 Correct 35 ms 64212 KB Output is correct
5 Correct 31 ms 63932 KB Output is correct
6 Correct 30 ms 63956 KB Output is correct
7 Correct 34 ms 64240 KB Output is correct
8 Correct 34 ms 64188 KB Output is correct
9 Correct 35 ms 64196 KB Output is correct
10 Correct 35 ms 64244 KB Output is correct
11 Correct 38 ms 64256 KB Output is correct
12 Correct 34 ms 64212 KB Output is correct
13 Correct 30 ms 64036 KB Output is correct
14 Correct 30 ms 63972 KB Output is correct
15 Correct 34 ms 64104 KB Output is correct
16 Correct 35 ms 64224 KB Output is correct
17 Correct 38 ms 64076 KB Output is correct
18 Correct 35 ms 64212 KB Output is correct
19 Correct 32 ms 64064 KB Output is correct
20 Correct 32 ms 64048 KB Output is correct
21 Correct 34 ms 64092 KB Output is correct
22 Correct 34 ms 64148 KB Output is correct
23 Correct 35 ms 64188 KB Output is correct
24 Correct 34 ms 64204 KB Output is correct
25 Correct 30 ms 64044 KB Output is correct
26 Correct 31 ms 63936 KB Output is correct
27 Correct 34 ms 64176 KB Output is correct
28 Correct 35 ms 64236 KB Output is correct
29 Correct 35 ms 64240 KB Output is correct
30 Correct 35 ms 64196 KB Output is correct
31 Correct 36 ms 64240 KB Output is correct
32 Correct 36 ms 64248 KB Output is correct
33 Correct 30 ms 64040 KB Output is correct
34 Correct 32 ms 63956 KB Output is correct
35 Correct 34 ms 64268 KB Output is correct
36 Correct 36 ms 64324 KB Output is correct
37 Correct 31 ms 64068 KB Output is correct
38 Correct 33 ms 64104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 203 ms 75284 KB Output is correct
2 Correct 187 ms 74672 KB Output is correct
3 Correct 226 ms 75540 KB Output is correct
4 Correct 212 ms 75604 KB Output is correct
5 Correct 213 ms 75052 KB Output is correct
6 Correct 238 ms 74968 KB Output is correct
7 Correct 58 ms 69604 KB Output is correct
8 Correct 60 ms 69748 KB Output is correct
9 Correct 220 ms 75576 KB Output is correct
10 Correct 227 ms 75852 KB Output is correct
11 Correct 219 ms 75716 KB Output is correct
12 Correct 230 ms 75816 KB Output is correct
13 Correct 143 ms 72704 KB Output is correct
14 Correct 157 ms 73684 KB Output is correct
15 Correct 135 ms 72056 KB Output is correct
16 Correct 133 ms 72404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 117420 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 64084 KB Output is correct
2 Correct 37 ms 64240 KB Output is correct
3 Correct 33 ms 64080 KB Output is correct
4 Correct 35 ms 64212 KB Output is correct
5 Correct 31 ms 63932 KB Output is correct
6 Correct 30 ms 63956 KB Output is correct
7 Correct 34 ms 64240 KB Output is correct
8 Correct 34 ms 64188 KB Output is correct
9 Correct 35 ms 64196 KB Output is correct
10 Correct 35 ms 64244 KB Output is correct
11 Correct 38 ms 64256 KB Output is correct
12 Correct 34 ms 64212 KB Output is correct
13 Correct 30 ms 64036 KB Output is correct
14 Correct 30 ms 63972 KB Output is correct
15 Correct 34 ms 64104 KB Output is correct
16 Correct 35 ms 64224 KB Output is correct
17 Correct 38 ms 64076 KB Output is correct
18 Correct 35 ms 64212 KB Output is correct
19 Correct 32 ms 64064 KB Output is correct
20 Correct 32 ms 64048 KB Output is correct
21 Correct 203 ms 75284 KB Output is correct
22 Correct 187 ms 74672 KB Output is correct
23 Correct 226 ms 75540 KB Output is correct
24 Correct 212 ms 75604 KB Output is correct
25 Correct 213 ms 75052 KB Output is correct
26 Correct 238 ms 74968 KB Output is correct
27 Correct 58 ms 69604 KB Output is correct
28 Correct 60 ms 69748 KB Output is correct
29 Correct 220 ms 75576 KB Output is correct
30 Correct 227 ms 75852 KB Output is correct
31 Correct 219 ms 75716 KB Output is correct
32 Correct 230 ms 75816 KB Output is correct
33 Correct 143 ms 72704 KB Output is correct
34 Correct 157 ms 73684 KB Output is correct
35 Correct 135 ms 72056 KB Output is correct
36 Correct 133 ms 72404 KB Output is correct
37 Correct 272 ms 76784 KB Output is correct
38 Correct 274 ms 76388 KB Output is correct
39 Correct 57 ms 69132 KB Output is correct
40 Correct 61 ms 69644 KB Output is correct
41 Correct 338 ms 78608 KB Output is correct
42 Correct 361 ms 79132 KB Output is correct
43 Correct 347 ms 79048 KB Output is correct
44 Correct 340 ms 78788 KB Output is correct
45 Correct 351 ms 79064 KB Output is correct
46 Correct 340 ms 78988 KB Output is correct
47 Correct 77 ms 70156 KB Output is correct
48 Correct 345 ms 78876 KB Output is correct
49 Correct 248 ms 75244 KB Output is correct
50 Correct 313 ms 77476 KB Output is correct
51 Correct 357 ms 79324 KB Output is correct
52 Correct 397 ms 79328 KB Output is correct
53 Correct 112 ms 71064 KB Output is correct
54 Correct 132 ms 72332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 224 ms 75008 KB Output is correct
2 Correct 245 ms 75588 KB Output is correct
3 Correct 261 ms 76036 KB Output is correct
4 Correct 194 ms 73292 KB Output is correct
5 Correct 224 ms 74864 KB Output is correct
6 Correct 262 ms 76200 KB Output is correct
7 Correct 60 ms 69552 KB Output is correct
8 Correct 66 ms 69420 KB Output is correct
9 Correct 72 ms 70340 KB Output is correct
10 Correct 206 ms 72792 KB Output is correct
11 Correct 285 ms 76076 KB Output is correct
12 Correct 279 ms 76028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 64084 KB Output is correct
2 Correct 37 ms 64240 KB Output is correct
3 Correct 33 ms 64080 KB Output is correct
4 Correct 35 ms 64212 KB Output is correct
5 Correct 31 ms 63932 KB Output is correct
6 Correct 30 ms 63956 KB Output is correct
7 Correct 34 ms 64240 KB Output is correct
8 Correct 34 ms 64188 KB Output is correct
9 Correct 35 ms 64196 KB Output is correct
10 Correct 35 ms 64244 KB Output is correct
11 Correct 38 ms 64256 KB Output is correct
12 Correct 34 ms 64212 KB Output is correct
13 Correct 30 ms 64036 KB Output is correct
14 Correct 30 ms 63972 KB Output is correct
15 Correct 34 ms 64104 KB Output is correct
16 Correct 35 ms 64224 KB Output is correct
17 Correct 38 ms 64076 KB Output is correct
18 Correct 35 ms 64212 KB Output is correct
19 Correct 32 ms 64064 KB Output is correct
20 Correct 32 ms 64048 KB Output is correct
21 Correct 34 ms 64092 KB Output is correct
22 Correct 34 ms 64148 KB Output is correct
23 Correct 35 ms 64188 KB Output is correct
24 Correct 34 ms 64204 KB Output is correct
25 Correct 30 ms 64044 KB Output is correct
26 Correct 31 ms 63936 KB Output is correct
27 Correct 34 ms 64176 KB Output is correct
28 Correct 35 ms 64236 KB Output is correct
29 Correct 35 ms 64240 KB Output is correct
30 Correct 35 ms 64196 KB Output is correct
31 Correct 36 ms 64240 KB Output is correct
32 Correct 36 ms 64248 KB Output is correct
33 Correct 30 ms 64040 KB Output is correct
34 Correct 32 ms 63956 KB Output is correct
35 Correct 34 ms 64268 KB Output is correct
36 Correct 36 ms 64324 KB Output is correct
37 Correct 31 ms 64068 KB Output is correct
38 Correct 33 ms 64104 KB Output is correct
39 Correct 203 ms 75284 KB Output is correct
40 Correct 187 ms 74672 KB Output is correct
41 Correct 226 ms 75540 KB Output is correct
42 Correct 212 ms 75604 KB Output is correct
43 Correct 213 ms 75052 KB Output is correct
44 Correct 238 ms 74968 KB Output is correct
45 Correct 58 ms 69604 KB Output is correct
46 Correct 60 ms 69748 KB Output is correct
47 Correct 220 ms 75576 KB Output is correct
48 Correct 227 ms 75852 KB Output is correct
49 Correct 219 ms 75716 KB Output is correct
50 Correct 230 ms 75816 KB Output is correct
51 Correct 143 ms 72704 KB Output is correct
52 Correct 157 ms 73684 KB Output is correct
53 Correct 135 ms 72056 KB Output is correct
54 Correct 133 ms 72404 KB Output is correct
55 Correct 272 ms 76784 KB Output is correct
56 Correct 274 ms 76388 KB Output is correct
57 Correct 57 ms 69132 KB Output is correct
58 Correct 61 ms 69644 KB Output is correct
59 Correct 338 ms 78608 KB Output is correct
60 Correct 361 ms 79132 KB Output is correct
61 Correct 347 ms 79048 KB Output is correct
62 Correct 340 ms 78788 KB Output is correct
63 Correct 351 ms 79064 KB Output is correct
64 Correct 340 ms 78988 KB Output is correct
65 Correct 77 ms 70156 KB Output is correct
66 Correct 345 ms 78876 KB Output is correct
67 Correct 248 ms 75244 KB Output is correct
68 Correct 313 ms 77476 KB Output is correct
69 Correct 357 ms 79324 KB Output is correct
70 Correct 397 ms 79328 KB Output is correct
71 Correct 112 ms 71064 KB Output is correct
72 Correct 132 ms 72332 KB Output is correct
73 Correct 224 ms 75008 KB Output is correct
74 Correct 245 ms 75588 KB Output is correct
75 Correct 261 ms 76036 KB Output is correct
76 Correct 194 ms 73292 KB Output is correct
77 Correct 224 ms 74864 KB Output is correct
78 Correct 262 ms 76200 KB Output is correct
79 Correct 60 ms 69552 KB Output is correct
80 Correct 66 ms 69420 KB Output is correct
81 Correct 72 ms 70340 KB Output is correct
82 Correct 206 ms 72792 KB Output is correct
83 Correct 285 ms 76076 KB Output is correct
84 Correct 279 ms 76028 KB Output is correct
85 Correct 283 ms 76800 KB Output is correct
86 Correct 311 ms 78136 KB Output is correct
87 Correct 306 ms 77300 KB Output is correct
88 Correct 343 ms 78824 KB Output is correct
89 Correct 224 ms 74552 KB Output is correct
90 Correct 352 ms 79024 KB Output is correct
91 Correct 285 ms 76448 KB Output is correct
92 Correct 260 ms 75992 KB Output is correct
93 Correct 361 ms 79024 KB Output is correct
94 Correct 350 ms 78816 KB Output is correct
95 Correct 341 ms 78620 KB Output is correct
96 Correct 355 ms 79060 KB Output is correct
97 Correct 355 ms 79064 KB Output is correct
98 Correct 304 ms 76924 KB Output is correct
99 Correct 68 ms 70044 KB Output is correct
100 Correct 280 ms 76520 KB Output is correct
101 Correct 350 ms 78812 KB Output is correct
102 Correct 201 ms 74828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 64084 KB Output is correct
2 Correct 37 ms 64240 KB Output is correct
3 Correct 33 ms 64080 KB Output is correct
4 Correct 35 ms 64212 KB Output is correct
5 Correct 31 ms 63932 KB Output is correct
6 Correct 30 ms 63956 KB Output is correct
7 Correct 34 ms 64240 KB Output is correct
8 Correct 34 ms 64188 KB Output is correct
9 Correct 35 ms 64196 KB Output is correct
10 Correct 35 ms 64244 KB Output is correct
11 Correct 38 ms 64256 KB Output is correct
12 Correct 34 ms 64212 KB Output is correct
13 Correct 30 ms 64036 KB Output is correct
14 Correct 30 ms 63972 KB Output is correct
15 Correct 34 ms 64104 KB Output is correct
16 Correct 35 ms 64224 KB Output is correct
17 Correct 38 ms 64076 KB Output is correct
18 Correct 35 ms 64212 KB Output is correct
19 Correct 32 ms 64064 KB Output is correct
20 Correct 32 ms 64048 KB Output is correct
21 Correct 34 ms 64092 KB Output is correct
22 Correct 34 ms 64148 KB Output is correct
23 Correct 35 ms 64188 KB Output is correct
24 Correct 34 ms 64204 KB Output is correct
25 Correct 30 ms 64044 KB Output is correct
26 Correct 31 ms 63936 KB Output is correct
27 Correct 34 ms 64176 KB Output is correct
28 Correct 35 ms 64236 KB Output is correct
29 Correct 35 ms 64240 KB Output is correct
30 Correct 35 ms 64196 KB Output is correct
31 Correct 36 ms 64240 KB Output is correct
32 Correct 36 ms 64248 KB Output is correct
33 Correct 30 ms 64040 KB Output is correct
34 Correct 32 ms 63956 KB Output is correct
35 Correct 34 ms 64268 KB Output is correct
36 Correct 36 ms 64324 KB Output is correct
37 Correct 31 ms 64068 KB Output is correct
38 Correct 33 ms 64104 KB Output is correct
39 Correct 203 ms 75284 KB Output is correct
40 Correct 187 ms 74672 KB Output is correct
41 Correct 226 ms 75540 KB Output is correct
42 Correct 212 ms 75604 KB Output is correct
43 Correct 213 ms 75052 KB Output is correct
44 Correct 238 ms 74968 KB Output is correct
45 Correct 58 ms 69604 KB Output is correct
46 Correct 60 ms 69748 KB Output is correct
47 Correct 220 ms 75576 KB Output is correct
48 Correct 227 ms 75852 KB Output is correct
49 Correct 219 ms 75716 KB Output is correct
50 Correct 230 ms 75816 KB Output is correct
51 Correct 143 ms 72704 KB Output is correct
52 Correct 157 ms 73684 KB Output is correct
53 Correct 135 ms 72056 KB Output is correct
54 Correct 133 ms 72404 KB Output is correct
55 Execution timed out 1096 ms 117420 KB Time limit exceeded
56 Halted 0 ms 0 KB -