Submission #794935

# Submission time Handle Problem Language Result Execution time Memory
794935 2023-07-27T04:12:28 Z RushB Food Court (JOI21_foodcourt) C++17
68 / 100
329 ms 95964 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
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 = 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(long long int, long long int, long long int, long long int, long long int, long long int)':
foodcourt.cpp:47:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |         int m = l + r >> 1;
      |                 ~~^~~
foodcourt.cpp: In function 'll get(long long int, long long int, long long int, long long int, long long int)':
foodcourt.cpp:60:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |         int m = l + r >> 1;
      |                 ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 30 ms 64024 KB Output is correct
2 Correct 30 ms 64176 KB Output is correct
3 Correct 31 ms 64084 KB Output is correct
4 Correct 31 ms 64176 KB Output is correct
5 Correct 30 ms 64152 KB Output is correct
6 Correct 30 ms 64100 KB Output is correct
7 Correct 33 ms 64128 KB Output is correct
8 Correct 31 ms 64084 KB Output is correct
9 Correct 31 ms 64160 KB Output is correct
10 Correct 36 ms 64256 KB Output is correct
11 Correct 31 ms 64084 KB Output is correct
12 Correct 31 ms 64088 KB Output is correct
13 Correct 30 ms 64120 KB Output is correct
14 Correct 30 ms 64072 KB Output is correct
15 Correct 30 ms 64040 KB Output is correct
16 Correct 30 ms 64132 KB Output is correct
17 Correct 30 ms 64128 KB Output is correct
18 Correct 31 ms 64088 KB Output is correct
19 Correct 31 ms 64056 KB Output is correct
20 Correct 31 ms 64084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 64024 KB Output is correct
2 Correct 30 ms 64176 KB Output is correct
3 Correct 31 ms 64084 KB Output is correct
4 Correct 31 ms 64176 KB Output is correct
5 Correct 30 ms 64152 KB Output is correct
6 Correct 30 ms 64100 KB Output is correct
7 Correct 33 ms 64128 KB Output is correct
8 Correct 31 ms 64084 KB Output is correct
9 Correct 31 ms 64160 KB Output is correct
10 Correct 36 ms 64256 KB Output is correct
11 Correct 31 ms 64084 KB Output is correct
12 Correct 31 ms 64088 KB Output is correct
13 Correct 30 ms 64120 KB Output is correct
14 Correct 30 ms 64072 KB Output is correct
15 Correct 30 ms 64040 KB Output is correct
16 Correct 30 ms 64132 KB Output is correct
17 Correct 30 ms 64128 KB Output is correct
18 Correct 31 ms 64088 KB Output is correct
19 Correct 31 ms 64056 KB Output is correct
20 Correct 31 ms 64084 KB Output is correct
21 Correct 31 ms 64168 KB Output is correct
22 Correct 32 ms 64176 KB Output is correct
23 Correct 31 ms 64060 KB Output is correct
24 Correct 31 ms 64100 KB Output is correct
25 Correct 31 ms 64056 KB Output is correct
26 Correct 30 ms 64084 KB Output is correct
27 Correct 35 ms 64044 KB Output is correct
28 Correct 31 ms 64096 KB Output is correct
29 Correct 31 ms 64176 KB Output is correct
30 Correct 31 ms 64124 KB Output is correct
31 Correct 31 ms 64132 KB Output is correct
32 Correct 31 ms 64084 KB Output is correct
33 Correct 31 ms 64168 KB Output is correct
34 Correct 30 ms 64176 KB Output is correct
35 Correct 31 ms 64116 KB Output is correct
36 Correct 31 ms 64084 KB Output is correct
37 Correct 31 ms 64004 KB Output is correct
38 Correct 31 ms 64080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 73644 KB Output is correct
2 Correct 83 ms 73676 KB Output is correct
3 Correct 79 ms 73548 KB Output is correct
4 Correct 82 ms 73644 KB Output is correct
5 Correct 82 ms 73708 KB Output is correct
6 Correct 88 ms 73712 KB Output is correct
7 Correct 54 ms 72056 KB Output is correct
8 Correct 55 ms 72288 KB Output is correct
9 Correct 82 ms 73296 KB Output is correct
10 Correct 83 ms 73720 KB Output is correct
11 Correct 95 ms 73804 KB Output is correct
12 Correct 82 ms 73744 KB Output is correct
13 Correct 73 ms 72752 KB Output is correct
14 Correct 80 ms 73548 KB Output is correct
15 Correct 81 ms 73548 KB Output is correct
16 Correct 83 ms 73692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 329 ms 95964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 64024 KB Output is correct
2 Correct 30 ms 64176 KB Output is correct
3 Correct 31 ms 64084 KB Output is correct
4 Correct 31 ms 64176 KB Output is correct
5 Correct 30 ms 64152 KB Output is correct
6 Correct 30 ms 64100 KB Output is correct
7 Correct 33 ms 64128 KB Output is correct
8 Correct 31 ms 64084 KB Output is correct
9 Correct 31 ms 64160 KB Output is correct
10 Correct 36 ms 64256 KB Output is correct
11 Correct 31 ms 64084 KB Output is correct
12 Correct 31 ms 64088 KB Output is correct
13 Correct 30 ms 64120 KB Output is correct
14 Correct 30 ms 64072 KB Output is correct
15 Correct 30 ms 64040 KB Output is correct
16 Correct 30 ms 64132 KB Output is correct
17 Correct 30 ms 64128 KB Output is correct
18 Correct 31 ms 64088 KB Output is correct
19 Correct 31 ms 64056 KB Output is correct
20 Correct 31 ms 64084 KB Output is correct
21 Correct 86 ms 73644 KB Output is correct
22 Correct 83 ms 73676 KB Output is correct
23 Correct 79 ms 73548 KB Output is correct
24 Correct 82 ms 73644 KB Output is correct
25 Correct 82 ms 73708 KB Output is correct
26 Correct 88 ms 73712 KB Output is correct
27 Correct 54 ms 72056 KB Output is correct
28 Correct 55 ms 72288 KB Output is correct
29 Correct 82 ms 73296 KB Output is correct
30 Correct 83 ms 73720 KB Output is correct
31 Correct 95 ms 73804 KB Output is correct
32 Correct 82 ms 73744 KB Output is correct
33 Correct 73 ms 72752 KB Output is correct
34 Correct 80 ms 73548 KB Output is correct
35 Correct 81 ms 73548 KB Output is correct
36 Correct 83 ms 73692 KB Output is correct
37 Correct 77 ms 72908 KB Output is correct
38 Correct 75 ms 72112 KB Output is correct
39 Correct 52 ms 71440 KB Output is correct
40 Correct 56 ms 72016 KB Output is correct
41 Correct 82 ms 73208 KB Output is correct
42 Correct 94 ms 73720 KB Output is correct
43 Correct 88 ms 73676 KB Output is correct
44 Correct 83 ms 73540 KB Output is correct
45 Correct 86 ms 73708 KB Output is correct
46 Correct 89 ms 73728 KB Output is correct
47 Correct 61 ms 72620 KB Output is correct
48 Correct 74 ms 73540 KB Output is correct
49 Correct 70 ms 71512 KB Output is correct
50 Correct 77 ms 72552 KB Output is correct
51 Correct 85 ms 73772 KB Output is correct
52 Correct 98 ms 73928 KB Output is correct
53 Correct 71 ms 71968 KB Output is correct
54 Correct 81 ms 73696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 72544 KB Output is correct
2 Correct 81 ms 73272 KB Output is correct
3 Correct 82 ms 73360 KB Output is correct
4 Correct 67 ms 71120 KB Output is correct
5 Correct 76 ms 72296 KB Output is correct
6 Correct 82 ms 73352 KB Output is correct
7 Correct 57 ms 71732 KB Output is correct
8 Correct 56 ms 71360 KB Output is correct
9 Correct 66 ms 72620 KB Output is correct
10 Correct 62 ms 71072 KB Output is correct
11 Correct 79 ms 72976 KB Output is correct
12 Correct 76 ms 73044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 64024 KB Output is correct
2 Correct 30 ms 64176 KB Output is correct
3 Correct 31 ms 64084 KB Output is correct
4 Correct 31 ms 64176 KB Output is correct
5 Correct 30 ms 64152 KB Output is correct
6 Correct 30 ms 64100 KB Output is correct
7 Correct 33 ms 64128 KB Output is correct
8 Correct 31 ms 64084 KB Output is correct
9 Correct 31 ms 64160 KB Output is correct
10 Correct 36 ms 64256 KB Output is correct
11 Correct 31 ms 64084 KB Output is correct
12 Correct 31 ms 64088 KB Output is correct
13 Correct 30 ms 64120 KB Output is correct
14 Correct 30 ms 64072 KB Output is correct
15 Correct 30 ms 64040 KB Output is correct
16 Correct 30 ms 64132 KB Output is correct
17 Correct 30 ms 64128 KB Output is correct
18 Correct 31 ms 64088 KB Output is correct
19 Correct 31 ms 64056 KB Output is correct
20 Correct 31 ms 64084 KB Output is correct
21 Correct 31 ms 64168 KB Output is correct
22 Correct 32 ms 64176 KB Output is correct
23 Correct 31 ms 64060 KB Output is correct
24 Correct 31 ms 64100 KB Output is correct
25 Correct 31 ms 64056 KB Output is correct
26 Correct 30 ms 64084 KB Output is correct
27 Correct 35 ms 64044 KB Output is correct
28 Correct 31 ms 64096 KB Output is correct
29 Correct 31 ms 64176 KB Output is correct
30 Correct 31 ms 64124 KB Output is correct
31 Correct 31 ms 64132 KB Output is correct
32 Correct 31 ms 64084 KB Output is correct
33 Correct 31 ms 64168 KB Output is correct
34 Correct 30 ms 64176 KB Output is correct
35 Correct 31 ms 64116 KB Output is correct
36 Correct 31 ms 64084 KB Output is correct
37 Correct 31 ms 64004 KB Output is correct
38 Correct 31 ms 64080 KB Output is correct
39 Correct 86 ms 73644 KB Output is correct
40 Correct 83 ms 73676 KB Output is correct
41 Correct 79 ms 73548 KB Output is correct
42 Correct 82 ms 73644 KB Output is correct
43 Correct 82 ms 73708 KB Output is correct
44 Correct 88 ms 73712 KB Output is correct
45 Correct 54 ms 72056 KB Output is correct
46 Correct 55 ms 72288 KB Output is correct
47 Correct 82 ms 73296 KB Output is correct
48 Correct 83 ms 73720 KB Output is correct
49 Correct 95 ms 73804 KB Output is correct
50 Correct 82 ms 73744 KB Output is correct
51 Correct 73 ms 72752 KB Output is correct
52 Correct 80 ms 73548 KB Output is correct
53 Correct 81 ms 73548 KB Output is correct
54 Correct 83 ms 73692 KB Output is correct
55 Correct 77 ms 72908 KB Output is correct
56 Correct 75 ms 72112 KB Output is correct
57 Correct 52 ms 71440 KB Output is correct
58 Correct 56 ms 72016 KB Output is correct
59 Correct 82 ms 73208 KB Output is correct
60 Correct 94 ms 73720 KB Output is correct
61 Correct 88 ms 73676 KB Output is correct
62 Correct 83 ms 73540 KB Output is correct
63 Correct 86 ms 73708 KB Output is correct
64 Correct 89 ms 73728 KB Output is correct
65 Correct 61 ms 72620 KB Output is correct
66 Correct 74 ms 73540 KB Output is correct
67 Correct 70 ms 71512 KB Output is correct
68 Correct 77 ms 72552 KB Output is correct
69 Correct 85 ms 73772 KB Output is correct
70 Correct 98 ms 73928 KB Output is correct
71 Correct 71 ms 71968 KB Output is correct
72 Correct 81 ms 73696 KB Output is correct
73 Correct 76 ms 72544 KB Output is correct
74 Correct 81 ms 73272 KB Output is correct
75 Correct 82 ms 73360 KB Output is correct
76 Correct 67 ms 71120 KB Output is correct
77 Correct 76 ms 72296 KB Output is correct
78 Correct 82 ms 73352 KB Output is correct
79 Correct 57 ms 71732 KB Output is correct
80 Correct 56 ms 71360 KB Output is correct
81 Correct 66 ms 72620 KB Output is correct
82 Correct 62 ms 71072 KB Output is correct
83 Correct 79 ms 72976 KB Output is correct
84 Correct 76 ms 73044 KB Output is correct
85 Correct 79 ms 72896 KB Output is correct
86 Correct 86 ms 73704 KB Output is correct
87 Correct 79 ms 72800 KB Output is correct
88 Correct 91 ms 73788 KB Output is correct
89 Correct 74 ms 70860 KB Output is correct
90 Correct 87 ms 73664 KB Output is correct
91 Correct 76 ms 72400 KB Output is correct
92 Correct 78 ms 71932 KB Output is correct
93 Correct 99 ms 73720 KB Output is correct
94 Correct 91 ms 73488 KB Output is correct
95 Correct 84 ms 73528 KB Output is correct
96 Correct 90 ms 73704 KB Output is correct
97 Correct 88 ms 73896 KB Output is correct
98 Correct 85 ms 72692 KB Output is correct
99 Correct 64 ms 72668 KB Output is correct
100 Correct 71 ms 72312 KB Output is correct
101 Correct 77 ms 73640 KB Output is correct
102 Correct 82 ms 72932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 64024 KB Output is correct
2 Correct 30 ms 64176 KB Output is correct
3 Correct 31 ms 64084 KB Output is correct
4 Correct 31 ms 64176 KB Output is correct
5 Correct 30 ms 64152 KB Output is correct
6 Correct 30 ms 64100 KB Output is correct
7 Correct 33 ms 64128 KB Output is correct
8 Correct 31 ms 64084 KB Output is correct
9 Correct 31 ms 64160 KB Output is correct
10 Correct 36 ms 64256 KB Output is correct
11 Correct 31 ms 64084 KB Output is correct
12 Correct 31 ms 64088 KB Output is correct
13 Correct 30 ms 64120 KB Output is correct
14 Correct 30 ms 64072 KB Output is correct
15 Correct 30 ms 64040 KB Output is correct
16 Correct 30 ms 64132 KB Output is correct
17 Correct 30 ms 64128 KB Output is correct
18 Correct 31 ms 64088 KB Output is correct
19 Correct 31 ms 64056 KB Output is correct
20 Correct 31 ms 64084 KB Output is correct
21 Correct 31 ms 64168 KB Output is correct
22 Correct 32 ms 64176 KB Output is correct
23 Correct 31 ms 64060 KB Output is correct
24 Correct 31 ms 64100 KB Output is correct
25 Correct 31 ms 64056 KB Output is correct
26 Correct 30 ms 64084 KB Output is correct
27 Correct 35 ms 64044 KB Output is correct
28 Correct 31 ms 64096 KB Output is correct
29 Correct 31 ms 64176 KB Output is correct
30 Correct 31 ms 64124 KB Output is correct
31 Correct 31 ms 64132 KB Output is correct
32 Correct 31 ms 64084 KB Output is correct
33 Correct 31 ms 64168 KB Output is correct
34 Correct 30 ms 64176 KB Output is correct
35 Correct 31 ms 64116 KB Output is correct
36 Correct 31 ms 64084 KB Output is correct
37 Correct 31 ms 64004 KB Output is correct
38 Correct 31 ms 64080 KB Output is correct
39 Correct 86 ms 73644 KB Output is correct
40 Correct 83 ms 73676 KB Output is correct
41 Correct 79 ms 73548 KB Output is correct
42 Correct 82 ms 73644 KB Output is correct
43 Correct 82 ms 73708 KB Output is correct
44 Correct 88 ms 73712 KB Output is correct
45 Correct 54 ms 72056 KB Output is correct
46 Correct 55 ms 72288 KB Output is correct
47 Correct 82 ms 73296 KB Output is correct
48 Correct 83 ms 73720 KB Output is correct
49 Correct 95 ms 73804 KB Output is correct
50 Correct 82 ms 73744 KB Output is correct
51 Correct 73 ms 72752 KB Output is correct
52 Correct 80 ms 73548 KB Output is correct
53 Correct 81 ms 73548 KB Output is correct
54 Correct 83 ms 73692 KB Output is correct
55 Incorrect 329 ms 95964 KB Output isn't correct
56 Halted 0 ms 0 KB -