답안 #794918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794918 2023-07-27T03:59:17 Z RushB 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
1000 ms 117500 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 (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, 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:74:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   74 |         int m = l + r >> 1;
      |                 ~~^~~
foodcourt.cpp: In function 'void solve(int, int, int)':
foodcourt.cpp:98:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   98 |                 int m = l + r >> 1;
      |                         ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 64084 KB Output is correct
2 Correct 34 ms 64216 KB Output is correct
3 Correct 34 ms 64148 KB Output is correct
4 Correct 35 ms 64188 KB Output is correct
5 Correct 31 ms 63992 KB Output is correct
6 Correct 36 ms 63956 KB Output is correct
7 Correct 37 ms 64460 KB Output is correct
8 Correct 35 ms 64224 KB Output is correct
9 Correct 36 ms 64184 KB Output is correct
10 Correct 38 ms 64196 KB Output is correct
11 Correct 36 ms 64268 KB Output is correct
12 Correct 36 ms 64208 KB Output is correct
13 Correct 32 ms 64040 KB Output is correct
14 Correct 36 ms 64072 KB Output is correct
15 Correct 34 ms 64084 KB Output is correct
16 Correct 36 ms 64240 KB Output is correct
17 Correct 34 ms 64128 KB Output is correct
18 Correct 36 ms 64212 KB Output is correct
19 Correct 33 ms 64032 KB Output is correct
20 Correct 33 ms 64112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 64084 KB Output is correct
2 Correct 34 ms 64216 KB Output is correct
3 Correct 34 ms 64148 KB Output is correct
4 Correct 35 ms 64188 KB Output is correct
5 Correct 31 ms 63992 KB Output is correct
6 Correct 36 ms 63956 KB Output is correct
7 Correct 37 ms 64460 KB Output is correct
8 Correct 35 ms 64224 KB Output is correct
9 Correct 36 ms 64184 KB Output is correct
10 Correct 38 ms 64196 KB Output is correct
11 Correct 36 ms 64268 KB Output is correct
12 Correct 36 ms 64208 KB Output is correct
13 Correct 32 ms 64040 KB Output is correct
14 Correct 36 ms 64072 KB Output is correct
15 Correct 34 ms 64084 KB Output is correct
16 Correct 36 ms 64240 KB Output is correct
17 Correct 34 ms 64128 KB Output is correct
18 Correct 36 ms 64212 KB Output is correct
19 Correct 33 ms 64032 KB Output is correct
20 Correct 33 ms 64112 KB Output is correct
21 Correct 35 ms 64108 KB Output is correct
22 Correct 35 ms 64228 KB Output is correct
23 Correct 36 ms 64192 KB Output is correct
24 Correct 35 ms 64248 KB Output is correct
25 Correct 31 ms 64012 KB Output is correct
26 Correct 31 ms 63956 KB Output is correct
27 Correct 37 ms 64176 KB Output is correct
28 Correct 38 ms 64396 KB Output is correct
29 Correct 35 ms 64212 KB Output is correct
30 Correct 35 ms 64156 KB Output is correct
31 Correct 35 ms 64248 KB Output is correct
32 Correct 36 ms 64264 KB Output is correct
33 Correct 31 ms 63944 KB Output is correct
34 Correct 32 ms 63948 KB Output is correct
35 Correct 35 ms 64212 KB Output is correct
36 Correct 38 ms 64300 KB Output is correct
37 Correct 32 ms 63956 KB Output is correct
38 Correct 33 ms 64020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 205 ms 75328 KB Output is correct
2 Correct 195 ms 74632 KB Output is correct
3 Correct 218 ms 75608 KB Output is correct
4 Correct 234 ms 75572 KB Output is correct
5 Correct 206 ms 74996 KB Output is correct
6 Correct 204 ms 75052 KB Output is correct
7 Correct 65 ms 69712 KB Output is correct
8 Correct 61 ms 69828 KB Output is correct
9 Correct 231 ms 75500 KB Output is correct
10 Correct 237 ms 75704 KB Output is correct
11 Correct 298 ms 75744 KB Output is correct
12 Correct 230 ms 75784 KB Output is correct
13 Correct 152 ms 72784 KB Output is correct
14 Correct 198 ms 73648 KB Output is correct
15 Correct 175 ms 72096 KB Output is correct
16 Correct 134 ms 72352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1082 ms 117500 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 64084 KB Output is correct
2 Correct 34 ms 64216 KB Output is correct
3 Correct 34 ms 64148 KB Output is correct
4 Correct 35 ms 64188 KB Output is correct
5 Correct 31 ms 63992 KB Output is correct
6 Correct 36 ms 63956 KB Output is correct
7 Correct 37 ms 64460 KB Output is correct
8 Correct 35 ms 64224 KB Output is correct
9 Correct 36 ms 64184 KB Output is correct
10 Correct 38 ms 64196 KB Output is correct
11 Correct 36 ms 64268 KB Output is correct
12 Correct 36 ms 64208 KB Output is correct
13 Correct 32 ms 64040 KB Output is correct
14 Correct 36 ms 64072 KB Output is correct
15 Correct 34 ms 64084 KB Output is correct
16 Correct 36 ms 64240 KB Output is correct
17 Correct 34 ms 64128 KB Output is correct
18 Correct 36 ms 64212 KB Output is correct
19 Correct 33 ms 64032 KB Output is correct
20 Correct 33 ms 64112 KB Output is correct
21 Correct 205 ms 75328 KB Output is correct
22 Correct 195 ms 74632 KB Output is correct
23 Correct 218 ms 75608 KB Output is correct
24 Correct 234 ms 75572 KB Output is correct
25 Correct 206 ms 74996 KB Output is correct
26 Correct 204 ms 75052 KB Output is correct
27 Correct 65 ms 69712 KB Output is correct
28 Correct 61 ms 69828 KB Output is correct
29 Correct 231 ms 75500 KB Output is correct
30 Correct 237 ms 75704 KB Output is correct
31 Correct 298 ms 75744 KB Output is correct
32 Correct 230 ms 75784 KB Output is correct
33 Correct 152 ms 72784 KB Output is correct
34 Correct 198 ms 73648 KB Output is correct
35 Correct 175 ms 72096 KB Output is correct
36 Correct 134 ms 72352 KB Output is correct
37 Correct 281 ms 76788 KB Output is correct
38 Correct 290 ms 76368 KB Output is correct
39 Correct 59 ms 69124 KB Output is correct
40 Correct 64 ms 69664 KB Output is correct
41 Correct 343 ms 78604 KB Output is correct
42 Correct 359 ms 79112 KB Output is correct
43 Correct 353 ms 79008 KB Output is correct
44 Correct 346 ms 78820 KB Output is correct
45 Correct 354 ms 79052 KB Output is correct
46 Correct 364 ms 79076 KB Output is correct
47 Correct 74 ms 70092 KB Output is correct
48 Correct 359 ms 78896 KB Output is correct
49 Correct 251 ms 75252 KB Output is correct
50 Correct 326 ms 77472 KB Output is correct
51 Correct 364 ms 79348 KB Output is correct
52 Correct 382 ms 79432 KB Output is correct
53 Correct 114 ms 71088 KB Output is correct
54 Correct 135 ms 72340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 74952 KB Output is correct
2 Correct 261 ms 75564 KB Output is correct
3 Correct 264 ms 75964 KB Output is correct
4 Correct 201 ms 73260 KB Output is correct
5 Correct 293 ms 74828 KB Output is correct
6 Correct 265 ms 76208 KB Output is correct
7 Correct 65 ms 69584 KB Output is correct
8 Correct 61 ms 69444 KB Output is correct
9 Correct 76 ms 70384 KB Output is correct
10 Correct 208 ms 72780 KB Output is correct
11 Correct 293 ms 76072 KB Output is correct
12 Correct 295 ms 76088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 64084 KB Output is correct
2 Correct 34 ms 64216 KB Output is correct
3 Correct 34 ms 64148 KB Output is correct
4 Correct 35 ms 64188 KB Output is correct
5 Correct 31 ms 63992 KB Output is correct
6 Correct 36 ms 63956 KB Output is correct
7 Correct 37 ms 64460 KB Output is correct
8 Correct 35 ms 64224 KB Output is correct
9 Correct 36 ms 64184 KB Output is correct
10 Correct 38 ms 64196 KB Output is correct
11 Correct 36 ms 64268 KB Output is correct
12 Correct 36 ms 64208 KB Output is correct
13 Correct 32 ms 64040 KB Output is correct
14 Correct 36 ms 64072 KB Output is correct
15 Correct 34 ms 64084 KB Output is correct
16 Correct 36 ms 64240 KB Output is correct
17 Correct 34 ms 64128 KB Output is correct
18 Correct 36 ms 64212 KB Output is correct
19 Correct 33 ms 64032 KB Output is correct
20 Correct 33 ms 64112 KB Output is correct
21 Correct 35 ms 64108 KB Output is correct
22 Correct 35 ms 64228 KB Output is correct
23 Correct 36 ms 64192 KB Output is correct
24 Correct 35 ms 64248 KB Output is correct
25 Correct 31 ms 64012 KB Output is correct
26 Correct 31 ms 63956 KB Output is correct
27 Correct 37 ms 64176 KB Output is correct
28 Correct 38 ms 64396 KB Output is correct
29 Correct 35 ms 64212 KB Output is correct
30 Correct 35 ms 64156 KB Output is correct
31 Correct 35 ms 64248 KB Output is correct
32 Correct 36 ms 64264 KB Output is correct
33 Correct 31 ms 63944 KB Output is correct
34 Correct 32 ms 63948 KB Output is correct
35 Correct 35 ms 64212 KB Output is correct
36 Correct 38 ms 64300 KB Output is correct
37 Correct 32 ms 63956 KB Output is correct
38 Correct 33 ms 64020 KB Output is correct
39 Correct 205 ms 75328 KB Output is correct
40 Correct 195 ms 74632 KB Output is correct
41 Correct 218 ms 75608 KB Output is correct
42 Correct 234 ms 75572 KB Output is correct
43 Correct 206 ms 74996 KB Output is correct
44 Correct 204 ms 75052 KB Output is correct
45 Correct 65 ms 69712 KB Output is correct
46 Correct 61 ms 69828 KB Output is correct
47 Correct 231 ms 75500 KB Output is correct
48 Correct 237 ms 75704 KB Output is correct
49 Correct 298 ms 75744 KB Output is correct
50 Correct 230 ms 75784 KB Output is correct
51 Correct 152 ms 72784 KB Output is correct
52 Correct 198 ms 73648 KB Output is correct
53 Correct 175 ms 72096 KB Output is correct
54 Correct 134 ms 72352 KB Output is correct
55 Correct 281 ms 76788 KB Output is correct
56 Correct 290 ms 76368 KB Output is correct
57 Correct 59 ms 69124 KB Output is correct
58 Correct 64 ms 69664 KB Output is correct
59 Correct 343 ms 78604 KB Output is correct
60 Correct 359 ms 79112 KB Output is correct
61 Correct 353 ms 79008 KB Output is correct
62 Correct 346 ms 78820 KB Output is correct
63 Correct 354 ms 79052 KB Output is correct
64 Correct 364 ms 79076 KB Output is correct
65 Correct 74 ms 70092 KB Output is correct
66 Correct 359 ms 78896 KB Output is correct
67 Correct 251 ms 75252 KB Output is correct
68 Correct 326 ms 77472 KB Output is correct
69 Correct 364 ms 79348 KB Output is correct
70 Correct 382 ms 79432 KB Output is correct
71 Correct 114 ms 71088 KB Output is correct
72 Correct 135 ms 72340 KB Output is correct
73 Correct 235 ms 74952 KB Output is correct
74 Correct 261 ms 75564 KB Output is correct
75 Correct 264 ms 75964 KB Output is correct
76 Correct 201 ms 73260 KB Output is correct
77 Correct 293 ms 74828 KB Output is correct
78 Correct 265 ms 76208 KB Output is correct
79 Correct 65 ms 69584 KB Output is correct
80 Correct 61 ms 69444 KB Output is correct
81 Correct 76 ms 70384 KB Output is correct
82 Correct 208 ms 72780 KB Output is correct
83 Correct 293 ms 76072 KB Output is correct
84 Correct 295 ms 76088 KB Output is correct
85 Correct 284 ms 76748 KB Output is correct
86 Correct 326 ms 78156 KB Output is correct
87 Correct 322 ms 77288 KB Output is correct
88 Correct 370 ms 78956 KB Output is correct
89 Correct 237 ms 74548 KB Output is correct
90 Correct 377 ms 79020 KB Output is correct
91 Correct 282 ms 76348 KB Output is correct
92 Correct 282 ms 75936 KB Output is correct
93 Correct 357 ms 79024 KB Output is correct
94 Correct 351 ms 78824 KB Output is correct
95 Correct 363 ms 78704 KB Output is correct
96 Correct 363 ms 79076 KB Output is correct
97 Correct 372 ms 79020 KB Output is correct
98 Correct 300 ms 76944 KB Output is correct
99 Correct 76 ms 70012 KB Output is correct
100 Correct 303 ms 76572 KB Output is correct
101 Correct 353 ms 78864 KB Output is correct
102 Correct 216 ms 74956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 64084 KB Output is correct
2 Correct 34 ms 64216 KB Output is correct
3 Correct 34 ms 64148 KB Output is correct
4 Correct 35 ms 64188 KB Output is correct
5 Correct 31 ms 63992 KB Output is correct
6 Correct 36 ms 63956 KB Output is correct
7 Correct 37 ms 64460 KB Output is correct
8 Correct 35 ms 64224 KB Output is correct
9 Correct 36 ms 64184 KB Output is correct
10 Correct 38 ms 64196 KB Output is correct
11 Correct 36 ms 64268 KB Output is correct
12 Correct 36 ms 64208 KB Output is correct
13 Correct 32 ms 64040 KB Output is correct
14 Correct 36 ms 64072 KB Output is correct
15 Correct 34 ms 64084 KB Output is correct
16 Correct 36 ms 64240 KB Output is correct
17 Correct 34 ms 64128 KB Output is correct
18 Correct 36 ms 64212 KB Output is correct
19 Correct 33 ms 64032 KB Output is correct
20 Correct 33 ms 64112 KB Output is correct
21 Correct 35 ms 64108 KB Output is correct
22 Correct 35 ms 64228 KB Output is correct
23 Correct 36 ms 64192 KB Output is correct
24 Correct 35 ms 64248 KB Output is correct
25 Correct 31 ms 64012 KB Output is correct
26 Correct 31 ms 63956 KB Output is correct
27 Correct 37 ms 64176 KB Output is correct
28 Correct 38 ms 64396 KB Output is correct
29 Correct 35 ms 64212 KB Output is correct
30 Correct 35 ms 64156 KB Output is correct
31 Correct 35 ms 64248 KB Output is correct
32 Correct 36 ms 64264 KB Output is correct
33 Correct 31 ms 63944 KB Output is correct
34 Correct 32 ms 63948 KB Output is correct
35 Correct 35 ms 64212 KB Output is correct
36 Correct 38 ms 64300 KB Output is correct
37 Correct 32 ms 63956 KB Output is correct
38 Correct 33 ms 64020 KB Output is correct
39 Correct 205 ms 75328 KB Output is correct
40 Correct 195 ms 74632 KB Output is correct
41 Correct 218 ms 75608 KB Output is correct
42 Correct 234 ms 75572 KB Output is correct
43 Correct 206 ms 74996 KB Output is correct
44 Correct 204 ms 75052 KB Output is correct
45 Correct 65 ms 69712 KB Output is correct
46 Correct 61 ms 69828 KB Output is correct
47 Correct 231 ms 75500 KB Output is correct
48 Correct 237 ms 75704 KB Output is correct
49 Correct 298 ms 75744 KB Output is correct
50 Correct 230 ms 75784 KB Output is correct
51 Correct 152 ms 72784 KB Output is correct
52 Correct 198 ms 73648 KB Output is correct
53 Correct 175 ms 72096 KB Output is correct
54 Correct 134 ms 72352 KB Output is correct
55 Execution timed out 1082 ms 117500 KB Time limit exceeded
56 Halted 0 ms 0 KB -