Submission #794933

# Submission time Handle Problem Language Result Execution time Memory
794933 2023-07-27T04:11:37 Z RushB Food Court (JOI21_foodcourt) C++17
68 / 100
193 ms 156312 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 = 2.6e5;
const int LG = 17;
long long B[N], mn[N], delta[N];
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(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];
}

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];
                        --R[i];
                        ad[L[i]].push_back({i, K[i]});
                        ad[R[i] + 1].push_back({i, -K[i]});
                }
                else if (t[i] == 2) {
                        cin >> L[i] >> R[i] >> K[i];
                        --L[i];
                        --R[i];
                        del[L[i]].push_back({i, K[i]});
                        del[R[i] + 1].push_back({i, -K[i]});
                }
                else {
                        cin >> A[i] >> B[i];
                        A[i]--;
                        GET[A[i]].push_back({B[i], i});
                }
        }
        FOR(i, 0, n) {
                for (auto [i, K]: del[i]) {
                        all.add(i, -K);
                        add(1, 0, q, i, q, -K);
                }
                for (auto [i, K]: ad[i]) {
                        pos.add(i, K);
                        all.add(i, K);
                        add(1, 0, q, i, q, K);
                }
                for (auto P: GET[i]) {
                        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);
                }
        }
        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(int, int, int, int, int, int)':
foodcourt.cpp:46:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |         int m = l + r >> 1;
      |                 ~~^~~
foodcourt.cpp: In function 'll get(int, int, int, int, int)':
foodcourt.cpp:59:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |         int m = l + r >> 1;
      |                 ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 27 ms 55596 KB Output is correct
2 Correct 27 ms 55604 KB Output is correct
3 Correct 27 ms 55512 KB Output is correct
4 Correct 28 ms 55600 KB Output is correct
5 Correct 27 ms 55600 KB Output is correct
6 Correct 27 ms 55636 KB Output is correct
7 Correct 27 ms 55596 KB Output is correct
8 Correct 26 ms 55624 KB Output is correct
9 Correct 26 ms 55600 KB Output is correct
10 Correct 27 ms 55576 KB Output is correct
11 Correct 26 ms 55628 KB Output is correct
12 Correct 27 ms 55568 KB Output is correct
13 Correct 26 ms 55636 KB Output is correct
14 Correct 28 ms 55556 KB Output is correct
15 Correct 26 ms 55480 KB Output is correct
16 Correct 27 ms 55544 KB Output is correct
17 Correct 27 ms 55636 KB Output is correct
18 Correct 27 ms 55580 KB Output is correct
19 Correct 27 ms 55612 KB Output is correct
20 Correct 27 ms 55616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 55596 KB Output is correct
2 Correct 27 ms 55604 KB Output is correct
3 Correct 27 ms 55512 KB Output is correct
4 Correct 28 ms 55600 KB Output is correct
5 Correct 27 ms 55600 KB Output is correct
6 Correct 27 ms 55636 KB Output is correct
7 Correct 27 ms 55596 KB Output is correct
8 Correct 26 ms 55624 KB Output is correct
9 Correct 26 ms 55600 KB Output is correct
10 Correct 27 ms 55576 KB Output is correct
11 Correct 26 ms 55628 KB Output is correct
12 Correct 27 ms 55568 KB Output is correct
13 Correct 26 ms 55636 KB Output is correct
14 Correct 28 ms 55556 KB Output is correct
15 Correct 26 ms 55480 KB Output is correct
16 Correct 27 ms 55544 KB Output is correct
17 Correct 27 ms 55636 KB Output is correct
18 Correct 27 ms 55580 KB Output is correct
19 Correct 27 ms 55612 KB Output is correct
20 Correct 27 ms 55616 KB Output is correct
21 Correct 27 ms 55568 KB Output is correct
22 Correct 27 ms 55636 KB Output is correct
23 Correct 27 ms 55520 KB Output is correct
24 Correct 27 ms 55628 KB Output is correct
25 Correct 27 ms 55616 KB Output is correct
26 Correct 27 ms 55552 KB Output is correct
27 Correct 26 ms 55580 KB Output is correct
28 Correct 29 ms 55528 KB Output is correct
29 Correct 28 ms 55588 KB Output is correct
30 Correct 31 ms 55636 KB Output is correct
31 Correct 26 ms 55636 KB Output is correct
32 Correct 27 ms 55580 KB Output is correct
33 Correct 27 ms 55584 KB Output is correct
34 Correct 28 ms 55620 KB Output is correct
35 Correct 27 ms 55508 KB Output is correct
36 Correct 27 ms 55636 KB Output is correct
37 Correct 27 ms 55508 KB Output is correct
38 Correct 27 ms 55636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 63244 KB Output is correct
2 Correct 75 ms 63288 KB Output is correct
3 Correct 73 ms 63300 KB Output is correct
4 Correct 73 ms 63316 KB Output is correct
5 Correct 83 ms 63268 KB Output is correct
6 Correct 79 ms 63256 KB Output is correct
7 Correct 49 ms 61724 KB Output is correct
8 Correct 56 ms 61840 KB Output is correct
9 Correct 75 ms 63036 KB Output is correct
10 Correct 77 ms 63276 KB Output is correct
11 Correct 90 ms 63324 KB Output is correct
12 Correct 79 ms 63312 KB Output is correct
13 Correct 71 ms 62444 KB Output is correct
14 Correct 74 ms 63064 KB Output is correct
15 Correct 74 ms 62632 KB Output is correct
16 Correct 73 ms 62824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 193 ms 156312 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 55596 KB Output is correct
2 Correct 27 ms 55604 KB Output is correct
3 Correct 27 ms 55512 KB Output is correct
4 Correct 28 ms 55600 KB Output is correct
5 Correct 27 ms 55600 KB Output is correct
6 Correct 27 ms 55636 KB Output is correct
7 Correct 27 ms 55596 KB Output is correct
8 Correct 26 ms 55624 KB Output is correct
9 Correct 26 ms 55600 KB Output is correct
10 Correct 27 ms 55576 KB Output is correct
11 Correct 26 ms 55628 KB Output is correct
12 Correct 27 ms 55568 KB Output is correct
13 Correct 26 ms 55636 KB Output is correct
14 Correct 28 ms 55556 KB Output is correct
15 Correct 26 ms 55480 KB Output is correct
16 Correct 27 ms 55544 KB Output is correct
17 Correct 27 ms 55636 KB Output is correct
18 Correct 27 ms 55580 KB Output is correct
19 Correct 27 ms 55612 KB Output is correct
20 Correct 27 ms 55616 KB Output is correct
21 Correct 75 ms 63244 KB Output is correct
22 Correct 75 ms 63288 KB Output is correct
23 Correct 73 ms 63300 KB Output is correct
24 Correct 73 ms 63316 KB Output is correct
25 Correct 83 ms 63268 KB Output is correct
26 Correct 79 ms 63256 KB Output is correct
27 Correct 49 ms 61724 KB Output is correct
28 Correct 56 ms 61840 KB Output is correct
29 Correct 75 ms 63036 KB Output is correct
30 Correct 77 ms 63276 KB Output is correct
31 Correct 90 ms 63324 KB Output is correct
32 Correct 79 ms 63312 KB Output is correct
33 Correct 71 ms 62444 KB Output is correct
34 Correct 74 ms 63064 KB Output is correct
35 Correct 74 ms 62632 KB Output is correct
36 Correct 73 ms 62824 KB Output is correct
37 Correct 78 ms 62668 KB Output is correct
38 Correct 68 ms 62156 KB Output is correct
39 Correct 47 ms 61008 KB Output is correct
40 Correct 51 ms 61540 KB Output is correct
41 Correct 76 ms 62864 KB Output is correct
42 Correct 77 ms 63332 KB Output is correct
43 Correct 78 ms 63316 KB Output is correct
44 Correct 79 ms 63052 KB Output is correct
45 Correct 83 ms 63288 KB Output is correct
46 Correct 93 ms 63352 KB Output is correct
47 Correct 57 ms 61968 KB Output is correct
48 Correct 69 ms 62388 KB Output is correct
49 Correct 62 ms 61540 KB Output is correct
50 Correct 70 ms 62540 KB Output is correct
51 Correct 86 ms 63356 KB Output is correct
52 Correct 79 ms 63336 KB Output is correct
53 Correct 65 ms 61756 KB Output is correct
54 Correct 74 ms 62800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 62496 KB Output is correct
2 Correct 76 ms 62860 KB Output is correct
3 Correct 84 ms 63052 KB Output is correct
4 Correct 63 ms 61376 KB Output is correct
5 Correct 70 ms 62284 KB Output is correct
6 Correct 77 ms 62996 KB Output is correct
7 Correct 54 ms 61524 KB Output is correct
8 Correct 57 ms 61320 KB Output is correct
9 Correct 62 ms 62192 KB Output is correct
10 Correct 58 ms 60952 KB Output is correct
11 Correct 71 ms 62380 KB Output is correct
12 Correct 71 ms 62300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 55596 KB Output is correct
2 Correct 27 ms 55604 KB Output is correct
3 Correct 27 ms 55512 KB Output is correct
4 Correct 28 ms 55600 KB Output is correct
5 Correct 27 ms 55600 KB Output is correct
6 Correct 27 ms 55636 KB Output is correct
7 Correct 27 ms 55596 KB Output is correct
8 Correct 26 ms 55624 KB Output is correct
9 Correct 26 ms 55600 KB Output is correct
10 Correct 27 ms 55576 KB Output is correct
11 Correct 26 ms 55628 KB Output is correct
12 Correct 27 ms 55568 KB Output is correct
13 Correct 26 ms 55636 KB Output is correct
14 Correct 28 ms 55556 KB Output is correct
15 Correct 26 ms 55480 KB Output is correct
16 Correct 27 ms 55544 KB Output is correct
17 Correct 27 ms 55636 KB Output is correct
18 Correct 27 ms 55580 KB Output is correct
19 Correct 27 ms 55612 KB Output is correct
20 Correct 27 ms 55616 KB Output is correct
21 Correct 27 ms 55568 KB Output is correct
22 Correct 27 ms 55636 KB Output is correct
23 Correct 27 ms 55520 KB Output is correct
24 Correct 27 ms 55628 KB Output is correct
25 Correct 27 ms 55616 KB Output is correct
26 Correct 27 ms 55552 KB Output is correct
27 Correct 26 ms 55580 KB Output is correct
28 Correct 29 ms 55528 KB Output is correct
29 Correct 28 ms 55588 KB Output is correct
30 Correct 31 ms 55636 KB Output is correct
31 Correct 26 ms 55636 KB Output is correct
32 Correct 27 ms 55580 KB Output is correct
33 Correct 27 ms 55584 KB Output is correct
34 Correct 28 ms 55620 KB Output is correct
35 Correct 27 ms 55508 KB Output is correct
36 Correct 27 ms 55636 KB Output is correct
37 Correct 27 ms 55508 KB Output is correct
38 Correct 27 ms 55636 KB Output is correct
39 Correct 75 ms 63244 KB Output is correct
40 Correct 75 ms 63288 KB Output is correct
41 Correct 73 ms 63300 KB Output is correct
42 Correct 73 ms 63316 KB Output is correct
43 Correct 83 ms 63268 KB Output is correct
44 Correct 79 ms 63256 KB Output is correct
45 Correct 49 ms 61724 KB Output is correct
46 Correct 56 ms 61840 KB Output is correct
47 Correct 75 ms 63036 KB Output is correct
48 Correct 77 ms 63276 KB Output is correct
49 Correct 90 ms 63324 KB Output is correct
50 Correct 79 ms 63312 KB Output is correct
51 Correct 71 ms 62444 KB Output is correct
52 Correct 74 ms 63064 KB Output is correct
53 Correct 74 ms 62632 KB Output is correct
54 Correct 73 ms 62824 KB Output is correct
55 Correct 78 ms 62668 KB Output is correct
56 Correct 68 ms 62156 KB Output is correct
57 Correct 47 ms 61008 KB Output is correct
58 Correct 51 ms 61540 KB Output is correct
59 Correct 76 ms 62864 KB Output is correct
60 Correct 77 ms 63332 KB Output is correct
61 Correct 78 ms 63316 KB Output is correct
62 Correct 79 ms 63052 KB Output is correct
63 Correct 83 ms 63288 KB Output is correct
64 Correct 93 ms 63352 KB Output is correct
65 Correct 57 ms 61968 KB Output is correct
66 Correct 69 ms 62388 KB Output is correct
67 Correct 62 ms 61540 KB Output is correct
68 Correct 70 ms 62540 KB Output is correct
69 Correct 86 ms 63356 KB Output is correct
70 Correct 79 ms 63336 KB Output is correct
71 Correct 65 ms 61756 KB Output is correct
72 Correct 74 ms 62800 KB Output is correct
73 Correct 83 ms 62496 KB Output is correct
74 Correct 76 ms 62860 KB Output is correct
75 Correct 84 ms 63052 KB Output is correct
76 Correct 63 ms 61376 KB Output is correct
77 Correct 70 ms 62284 KB Output is correct
78 Correct 77 ms 62996 KB Output is correct
79 Correct 54 ms 61524 KB Output is correct
80 Correct 57 ms 61320 KB Output is correct
81 Correct 62 ms 62192 KB Output is correct
82 Correct 58 ms 60952 KB Output is correct
83 Correct 71 ms 62380 KB Output is correct
84 Correct 71 ms 62300 KB Output is correct
85 Correct 76 ms 62772 KB Output is correct
86 Correct 81 ms 63328 KB Output is correct
87 Correct 75 ms 62500 KB Output is correct
88 Correct 84 ms 63252 KB Output is correct
89 Correct 62 ms 61232 KB Output is correct
90 Correct 81 ms 63280 KB Output is correct
91 Correct 76 ms 62168 KB Output is correct
92 Correct 69 ms 61920 KB Output is correct
93 Correct 81 ms 63308 KB Output is correct
94 Correct 80 ms 63052 KB Output is correct
95 Correct 79 ms 63172 KB Output is correct
96 Correct 81 ms 63248 KB Output is correct
97 Correct 80 ms 63308 KB Output is correct
98 Correct 73 ms 62408 KB Output is correct
99 Correct 58 ms 61932 KB Output is correct
100 Correct 71 ms 61656 KB Output is correct
101 Correct 72 ms 62512 KB Output is correct
102 Correct 76 ms 62412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 55596 KB Output is correct
2 Correct 27 ms 55604 KB Output is correct
3 Correct 27 ms 55512 KB Output is correct
4 Correct 28 ms 55600 KB Output is correct
5 Correct 27 ms 55600 KB Output is correct
6 Correct 27 ms 55636 KB Output is correct
7 Correct 27 ms 55596 KB Output is correct
8 Correct 26 ms 55624 KB Output is correct
9 Correct 26 ms 55600 KB Output is correct
10 Correct 27 ms 55576 KB Output is correct
11 Correct 26 ms 55628 KB Output is correct
12 Correct 27 ms 55568 KB Output is correct
13 Correct 26 ms 55636 KB Output is correct
14 Correct 28 ms 55556 KB Output is correct
15 Correct 26 ms 55480 KB Output is correct
16 Correct 27 ms 55544 KB Output is correct
17 Correct 27 ms 55636 KB Output is correct
18 Correct 27 ms 55580 KB Output is correct
19 Correct 27 ms 55612 KB Output is correct
20 Correct 27 ms 55616 KB Output is correct
21 Correct 27 ms 55568 KB Output is correct
22 Correct 27 ms 55636 KB Output is correct
23 Correct 27 ms 55520 KB Output is correct
24 Correct 27 ms 55628 KB Output is correct
25 Correct 27 ms 55616 KB Output is correct
26 Correct 27 ms 55552 KB Output is correct
27 Correct 26 ms 55580 KB Output is correct
28 Correct 29 ms 55528 KB Output is correct
29 Correct 28 ms 55588 KB Output is correct
30 Correct 31 ms 55636 KB Output is correct
31 Correct 26 ms 55636 KB Output is correct
32 Correct 27 ms 55580 KB Output is correct
33 Correct 27 ms 55584 KB Output is correct
34 Correct 28 ms 55620 KB Output is correct
35 Correct 27 ms 55508 KB Output is correct
36 Correct 27 ms 55636 KB Output is correct
37 Correct 27 ms 55508 KB Output is correct
38 Correct 27 ms 55636 KB Output is correct
39 Correct 75 ms 63244 KB Output is correct
40 Correct 75 ms 63288 KB Output is correct
41 Correct 73 ms 63300 KB Output is correct
42 Correct 73 ms 63316 KB Output is correct
43 Correct 83 ms 63268 KB Output is correct
44 Correct 79 ms 63256 KB Output is correct
45 Correct 49 ms 61724 KB Output is correct
46 Correct 56 ms 61840 KB Output is correct
47 Correct 75 ms 63036 KB Output is correct
48 Correct 77 ms 63276 KB Output is correct
49 Correct 90 ms 63324 KB Output is correct
50 Correct 79 ms 63312 KB Output is correct
51 Correct 71 ms 62444 KB Output is correct
52 Correct 74 ms 63064 KB Output is correct
53 Correct 74 ms 62632 KB Output is correct
54 Correct 73 ms 62824 KB Output is correct
55 Runtime error 193 ms 156312 KB Execution killed with signal 11
56 Halted 0 ms 0 KB -