답안 #794911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794911 2023-07-27T03:35:10 Z RushB 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
1000 ms 97296 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 
#define int int64_t
const int64_t INF = 1ll << 60;
const int N = 3e5;
const int LG = 20;
int A[N], B[N], L[N], R[N], K[N], C[N], n, m, q, mn[N << 2], delta[N << 2], ans[N];
vector<int> V[4 * N], GET[N];
short t[N];

struct fenw {
        int bit[N];
        void add(int r, int d) {
                r++;
                for (; r < N; r += r & -r)
                        bit[r] += d;
        }
        int get(int r) {
                r++;
                int re = 0;
                for (; r; r &= (r - 1)) 
                        re += bit[r];
                return re;
        }
        int find(int 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 (R <= l || r <= L) return;
        if (L <= l && r <= R) {
                mn[v] += d;
                delta[v] += d;
                return;
        }
        int m = l + r >> 1;
        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];
}
int 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]) {
                        int 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(int64_t, int64_t, int64_t, int64_t, int64_t, int64_t)':
foodcourt.cpp:44:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |         int m = l + r >> 1;
      |                 ~~^~~
foodcourt.cpp: In function 'void add(int64_t, int64_t, int64_t, int64_t, int64_t, int64_t)':
foodcourt.cpp:56:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |         int m = l + r >> 1;
      |                 ~~^~~
foodcourt.cpp: In function 'int64_t get(int64_t, int64_t, int64_t, int64_t, int64_t)':
foodcourt.cpp:64:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |         int m = l + r >> 1;
      |                 ~~^~~
foodcourt.cpp: In function 'void solve(int64_t, int64_t, int64_t)':
foodcourt.cpp:88:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   88 |                 int m = l + r >> 1;
      |                         ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 35920 KB Output is correct
2 Correct 23 ms 36048 KB Output is correct
3 Correct 21 ms 35924 KB Output is correct
4 Correct 22 ms 36132 KB Output is correct
5 Correct 22 ms 35856 KB Output is correct
6 Correct 18 ms 35912 KB Output is correct
7 Correct 23 ms 36080 KB Output is correct
8 Correct 23 ms 36140 KB Output is correct
9 Correct 23 ms 36156 KB Output is correct
10 Correct 23 ms 36136 KB Output is correct
11 Correct 23 ms 36040 KB Output is correct
12 Correct 23 ms 36092 KB Output is correct
13 Correct 19 ms 35832 KB Output is correct
14 Correct 23 ms 35980 KB Output is correct
15 Correct 26 ms 35964 KB Output is correct
16 Correct 26 ms 36180 KB Output is correct
17 Correct 22 ms 36068 KB Output is correct
18 Correct 23 ms 36136 KB Output is correct
19 Correct 20 ms 35960 KB Output is correct
20 Correct 20 ms 35980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 35920 KB Output is correct
2 Correct 23 ms 36048 KB Output is correct
3 Correct 21 ms 35924 KB Output is correct
4 Correct 22 ms 36132 KB Output is correct
5 Correct 22 ms 35856 KB Output is correct
6 Correct 18 ms 35912 KB Output is correct
7 Correct 23 ms 36080 KB Output is correct
8 Correct 23 ms 36140 KB Output is correct
9 Correct 23 ms 36156 KB Output is correct
10 Correct 23 ms 36136 KB Output is correct
11 Correct 23 ms 36040 KB Output is correct
12 Correct 23 ms 36092 KB Output is correct
13 Correct 19 ms 35832 KB Output is correct
14 Correct 23 ms 35980 KB Output is correct
15 Correct 26 ms 35964 KB Output is correct
16 Correct 26 ms 36180 KB Output is correct
17 Correct 22 ms 36068 KB Output is correct
18 Correct 23 ms 36136 KB Output is correct
19 Correct 20 ms 35960 KB Output is correct
20 Correct 20 ms 35980 KB Output is correct
21 Correct 21 ms 36108 KB Output is correct
22 Correct 23 ms 36180 KB Output is correct
23 Correct 23 ms 36088 KB Output is correct
24 Correct 23 ms 36052 KB Output is correct
25 Correct 22 ms 35844 KB Output is correct
26 Correct 22 ms 35960 KB Output is correct
27 Correct 27 ms 36088 KB Output is correct
28 Correct 24 ms 36180 KB Output is correct
29 Correct 23 ms 36080 KB Output is correct
30 Correct 23 ms 36084 KB Output is correct
31 Correct 23 ms 36084 KB Output is correct
32 Correct 30 ms 36144 KB Output is correct
33 Correct 19 ms 35908 KB Output is correct
34 Correct 19 ms 35960 KB Output is correct
35 Correct 23 ms 36140 KB Output is correct
36 Correct 24 ms 36172 KB Output is correct
37 Correct 23 ms 35960 KB Output is correct
38 Correct 20 ms 35956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 49364 KB Output is correct
2 Correct 200 ms 48716 KB Output is correct
3 Correct 247 ms 49584 KB Output is correct
4 Correct 222 ms 49568 KB Output is correct
5 Correct 203 ms 49052 KB Output is correct
6 Correct 202 ms 49080 KB Output is correct
7 Correct 49 ms 43544 KB Output is correct
8 Correct 50 ms 43656 KB Output is correct
9 Correct 225 ms 49568 KB Output is correct
10 Correct 262 ms 50000 KB Output is correct
11 Correct 222 ms 49740 KB Output is correct
12 Correct 223 ms 49928 KB Output is correct
13 Correct 139 ms 46716 KB Output is correct
14 Correct 153 ms 47852 KB Output is correct
15 Correct 126 ms 46552 KB Output is correct
16 Correct 123 ms 46884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1082 ms 97296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 35920 KB Output is correct
2 Correct 23 ms 36048 KB Output is correct
3 Correct 21 ms 35924 KB Output is correct
4 Correct 22 ms 36132 KB Output is correct
5 Correct 22 ms 35856 KB Output is correct
6 Correct 18 ms 35912 KB Output is correct
7 Correct 23 ms 36080 KB Output is correct
8 Correct 23 ms 36140 KB Output is correct
9 Correct 23 ms 36156 KB Output is correct
10 Correct 23 ms 36136 KB Output is correct
11 Correct 23 ms 36040 KB Output is correct
12 Correct 23 ms 36092 KB Output is correct
13 Correct 19 ms 35832 KB Output is correct
14 Correct 23 ms 35980 KB Output is correct
15 Correct 26 ms 35964 KB Output is correct
16 Correct 26 ms 36180 KB Output is correct
17 Correct 22 ms 36068 KB Output is correct
18 Correct 23 ms 36136 KB Output is correct
19 Correct 20 ms 35960 KB Output is correct
20 Correct 20 ms 35980 KB Output is correct
21 Correct 235 ms 49364 KB Output is correct
22 Correct 200 ms 48716 KB Output is correct
23 Correct 247 ms 49584 KB Output is correct
24 Correct 222 ms 49568 KB Output is correct
25 Correct 203 ms 49052 KB Output is correct
26 Correct 202 ms 49080 KB Output is correct
27 Correct 49 ms 43544 KB Output is correct
28 Correct 50 ms 43656 KB Output is correct
29 Correct 225 ms 49568 KB Output is correct
30 Correct 262 ms 50000 KB Output is correct
31 Correct 222 ms 49740 KB Output is correct
32 Correct 223 ms 49928 KB Output is correct
33 Correct 139 ms 46716 KB Output is correct
34 Correct 153 ms 47852 KB Output is correct
35 Correct 126 ms 46552 KB Output is correct
36 Correct 123 ms 46884 KB Output is correct
37 Correct 271 ms 50232 KB Output is correct
38 Correct 278 ms 49652 KB Output is correct
39 Correct 46 ms 42696 KB Output is correct
40 Correct 55 ms 43400 KB Output is correct
41 Correct 339 ms 52128 KB Output is correct
42 Correct 355 ms 52692 KB Output is correct
43 Correct 349 ms 52712 KB Output is correct
44 Correct 362 ms 52460 KB Output is correct
45 Correct 365 ms 52800 KB Output is correct
46 Correct 365 ms 52640 KB Output is correct
47 Correct 78 ms 44256 KB Output is correct
48 Correct 368 ms 52808 KB Output is correct
49 Correct 255 ms 48368 KB Output is correct
50 Correct 315 ms 50792 KB Output is correct
51 Correct 376 ms 52972 KB Output is correct
52 Correct 360 ms 52968 KB Output is correct
53 Correct 107 ms 45048 KB Output is correct
54 Correct 137 ms 46912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 237 ms 49476 KB Output is correct
2 Correct 249 ms 50380 KB Output is correct
3 Correct 256 ms 50884 KB Output is correct
4 Correct 191 ms 47376 KB Output is correct
5 Correct 231 ms 49260 KB Output is correct
6 Correct 272 ms 51128 KB Output is correct
7 Correct 51 ms 43788 KB Output is correct
8 Correct 49 ms 43340 KB Output is correct
9 Correct 62 ms 45172 KB Output is correct
10 Correct 206 ms 46808 KB Output is correct
11 Correct 297 ms 50940 KB Output is correct
12 Correct 296 ms 50972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 35920 KB Output is correct
2 Correct 23 ms 36048 KB Output is correct
3 Correct 21 ms 35924 KB Output is correct
4 Correct 22 ms 36132 KB Output is correct
5 Correct 22 ms 35856 KB Output is correct
6 Correct 18 ms 35912 KB Output is correct
7 Correct 23 ms 36080 KB Output is correct
8 Correct 23 ms 36140 KB Output is correct
9 Correct 23 ms 36156 KB Output is correct
10 Correct 23 ms 36136 KB Output is correct
11 Correct 23 ms 36040 KB Output is correct
12 Correct 23 ms 36092 KB Output is correct
13 Correct 19 ms 35832 KB Output is correct
14 Correct 23 ms 35980 KB Output is correct
15 Correct 26 ms 35964 KB Output is correct
16 Correct 26 ms 36180 KB Output is correct
17 Correct 22 ms 36068 KB Output is correct
18 Correct 23 ms 36136 KB Output is correct
19 Correct 20 ms 35960 KB Output is correct
20 Correct 20 ms 35980 KB Output is correct
21 Correct 21 ms 36108 KB Output is correct
22 Correct 23 ms 36180 KB Output is correct
23 Correct 23 ms 36088 KB Output is correct
24 Correct 23 ms 36052 KB Output is correct
25 Correct 22 ms 35844 KB Output is correct
26 Correct 22 ms 35960 KB Output is correct
27 Correct 27 ms 36088 KB Output is correct
28 Correct 24 ms 36180 KB Output is correct
29 Correct 23 ms 36080 KB Output is correct
30 Correct 23 ms 36084 KB Output is correct
31 Correct 23 ms 36084 KB Output is correct
32 Correct 30 ms 36144 KB Output is correct
33 Correct 19 ms 35908 KB Output is correct
34 Correct 19 ms 35960 KB Output is correct
35 Correct 23 ms 36140 KB Output is correct
36 Correct 24 ms 36172 KB Output is correct
37 Correct 23 ms 35960 KB Output is correct
38 Correct 20 ms 35956 KB Output is correct
39 Correct 235 ms 49364 KB Output is correct
40 Correct 200 ms 48716 KB Output is correct
41 Correct 247 ms 49584 KB Output is correct
42 Correct 222 ms 49568 KB Output is correct
43 Correct 203 ms 49052 KB Output is correct
44 Correct 202 ms 49080 KB Output is correct
45 Correct 49 ms 43544 KB Output is correct
46 Correct 50 ms 43656 KB Output is correct
47 Correct 225 ms 49568 KB Output is correct
48 Correct 262 ms 50000 KB Output is correct
49 Correct 222 ms 49740 KB Output is correct
50 Correct 223 ms 49928 KB Output is correct
51 Correct 139 ms 46716 KB Output is correct
52 Correct 153 ms 47852 KB Output is correct
53 Correct 126 ms 46552 KB Output is correct
54 Correct 123 ms 46884 KB Output is correct
55 Correct 271 ms 50232 KB Output is correct
56 Correct 278 ms 49652 KB Output is correct
57 Correct 46 ms 42696 KB Output is correct
58 Correct 55 ms 43400 KB Output is correct
59 Correct 339 ms 52128 KB Output is correct
60 Correct 355 ms 52692 KB Output is correct
61 Correct 349 ms 52712 KB Output is correct
62 Correct 362 ms 52460 KB Output is correct
63 Correct 365 ms 52800 KB Output is correct
64 Correct 365 ms 52640 KB Output is correct
65 Correct 78 ms 44256 KB Output is correct
66 Correct 368 ms 52808 KB Output is correct
67 Correct 255 ms 48368 KB Output is correct
68 Correct 315 ms 50792 KB Output is correct
69 Correct 376 ms 52972 KB Output is correct
70 Correct 360 ms 52968 KB Output is correct
71 Correct 107 ms 45048 KB Output is correct
72 Correct 137 ms 46912 KB Output is correct
73 Correct 237 ms 49476 KB Output is correct
74 Correct 249 ms 50380 KB Output is correct
75 Correct 256 ms 50884 KB Output is correct
76 Correct 191 ms 47376 KB Output is correct
77 Correct 231 ms 49260 KB Output is correct
78 Correct 272 ms 51128 KB Output is correct
79 Correct 51 ms 43788 KB Output is correct
80 Correct 49 ms 43340 KB Output is correct
81 Correct 62 ms 45172 KB Output is correct
82 Correct 206 ms 46808 KB Output is correct
83 Correct 297 ms 50940 KB Output is correct
84 Correct 296 ms 50972 KB Output is correct
85 Correct 281 ms 50756 KB Output is correct
86 Correct 327 ms 52364 KB Output is correct
87 Correct 311 ms 51284 KB Output is correct
88 Correct 352 ms 53144 KB Output is correct
89 Correct 283 ms 47824 KB Output is correct
90 Correct 347 ms 53160 KB Output is correct
91 Correct 298 ms 50180 KB Output is correct
92 Correct 263 ms 49584 KB Output is correct
93 Correct 368 ms 53180 KB Output is correct
94 Correct 346 ms 52924 KB Output is correct
95 Correct 356 ms 52732 KB Output is correct
96 Correct 409 ms 53176 KB Output is correct
97 Correct 368 ms 53200 KB Output is correct
98 Correct 291 ms 50676 KB Output is correct
99 Correct 61 ms 44740 KB Output is correct
100 Correct 313 ms 50060 KB Output is correct
101 Correct 388 ms 53256 KB Output is correct
102 Correct 213 ms 49016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 35920 KB Output is correct
2 Correct 23 ms 36048 KB Output is correct
3 Correct 21 ms 35924 KB Output is correct
4 Correct 22 ms 36132 KB Output is correct
5 Correct 22 ms 35856 KB Output is correct
6 Correct 18 ms 35912 KB Output is correct
7 Correct 23 ms 36080 KB Output is correct
8 Correct 23 ms 36140 KB Output is correct
9 Correct 23 ms 36156 KB Output is correct
10 Correct 23 ms 36136 KB Output is correct
11 Correct 23 ms 36040 KB Output is correct
12 Correct 23 ms 36092 KB Output is correct
13 Correct 19 ms 35832 KB Output is correct
14 Correct 23 ms 35980 KB Output is correct
15 Correct 26 ms 35964 KB Output is correct
16 Correct 26 ms 36180 KB Output is correct
17 Correct 22 ms 36068 KB Output is correct
18 Correct 23 ms 36136 KB Output is correct
19 Correct 20 ms 35960 KB Output is correct
20 Correct 20 ms 35980 KB Output is correct
21 Correct 21 ms 36108 KB Output is correct
22 Correct 23 ms 36180 KB Output is correct
23 Correct 23 ms 36088 KB Output is correct
24 Correct 23 ms 36052 KB Output is correct
25 Correct 22 ms 35844 KB Output is correct
26 Correct 22 ms 35960 KB Output is correct
27 Correct 27 ms 36088 KB Output is correct
28 Correct 24 ms 36180 KB Output is correct
29 Correct 23 ms 36080 KB Output is correct
30 Correct 23 ms 36084 KB Output is correct
31 Correct 23 ms 36084 KB Output is correct
32 Correct 30 ms 36144 KB Output is correct
33 Correct 19 ms 35908 KB Output is correct
34 Correct 19 ms 35960 KB Output is correct
35 Correct 23 ms 36140 KB Output is correct
36 Correct 24 ms 36172 KB Output is correct
37 Correct 23 ms 35960 KB Output is correct
38 Correct 20 ms 35956 KB Output is correct
39 Correct 235 ms 49364 KB Output is correct
40 Correct 200 ms 48716 KB Output is correct
41 Correct 247 ms 49584 KB Output is correct
42 Correct 222 ms 49568 KB Output is correct
43 Correct 203 ms 49052 KB Output is correct
44 Correct 202 ms 49080 KB Output is correct
45 Correct 49 ms 43544 KB Output is correct
46 Correct 50 ms 43656 KB Output is correct
47 Correct 225 ms 49568 KB Output is correct
48 Correct 262 ms 50000 KB Output is correct
49 Correct 222 ms 49740 KB Output is correct
50 Correct 223 ms 49928 KB Output is correct
51 Correct 139 ms 46716 KB Output is correct
52 Correct 153 ms 47852 KB Output is correct
53 Correct 126 ms 46552 KB Output is correct
54 Correct 123 ms 46884 KB Output is correct
55 Execution timed out 1082 ms 97296 KB Time limit exceeded
56 Halted 0 ms 0 KB -