답안 #1098085

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098085 2024-10-09T03:42:42 Z _callmelucian 푸드 코트 (JOI21_foodcourt) C++14
42 / 100
1000 ms 236056 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,ll> tt;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

const int mn = 250005;

struct IT {
    vector<ll> lo, hi, lazy;
    IT (int sz) : lo(4 * sz), hi(4 * sz), lazy(4 * sz) {}

    void apply (int k, ll val) {
        lo[k] += val, hi[k] += val, lazy[k] += val;
    }

    void pushDown (int k) {
        if (!lazy[k]) return;
        apply(2 * k, lazy[k]), apply(2 * k + 1, lazy[k]), lazy[k] = 0;
    }

    void update (int a, int b, ll val, int k, int l, int r) {
        if (b < l || r < a) return;
        if (a <= l && r <= b)
            return apply(k, val), void();
        pushDown(k);
        int mid = (l + r) >> 1;
        update(a, b, val, 2 * k, l, mid);
        update(a, b, val, 2 * k + 1, mid + 1, r);
        lo[k] = min(lo[2 * k], lo[2 * k + 1]);
        hi[k] = max(hi[2 * k], hi[2 * k + 1]);
    }

    void walk (ll cur, int k, int l, int r, vector<tt> &vec) {
        if (hi[k] == 0) return;
        if (lo[k] >= cur)
            return vec.emplace_back(l, r, cur), void();
        if (l == r)
            return vec.emplace_back(l, r, lo[k]), void();
        pushDown(k);
        int mid = (l + r) >> 1;
        walk(cur, 2 * k, l, mid, vec);
        walk(cur, 2 * k + 1, mid + 1, r, vec);
    }

    void breakDown (int a, int b, ll cur, int k, int l, int r, vector<tt> &vec) {
        if (b < l || r < a || hi[k] == 0) return;
        if (lo[k] >= cur)
            return vec.emplace_back(max(a, l), min(b, r), cur), void();
        if (a <= l && r <= b)
            return walk(cur, k, l, r, vec), void();
        pushDown(k);
        int mid = (l + r) >> 1;
        breakDown(a, b, cur, 2 * k, l, mid, vec);
        breakDown(a, b, cur, 2 * k + 1, mid + 1, r, vec);
    }
} tree(mn);

struct BIT {
    vector<ll> tr;
    BIT (int sz) : tr(sz + 1) {}

    int p (int k) { return k & -k; }

    void update (int pos, int val) {
        for (; pos < tr.size(); pos += p(pos)) tr[pos] += val;
    }

    ll preSum (int pos) {
        ll ans = 0;
        for (; pos; pos -= p(pos)) ans += tr[pos];
        return ans;
    }

    int walk (ll ub) {
        int ans = 0, lg = 31 - __builtin_clz(tr.size());
        ll sum = 0;
        for (int msk = (1 << lg); msk > 0; msk >>= 1) {
            if ((ans | msk) < tr.size() && tr[ans | msk] + sum < ub) ans |= msk, sum += tr[ans];
        }
        return ans;
    }
} customer(mn), cut(mn);

vector<pl> openCust[mn], openCut[mn], closeCust[mn], closeCut[mn], query[mn];
int group[mn], ans[mn];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, q; cin >> n >> m >> q;
    for (int i = 1; i <= q; i++) {
        int type; cin >> type;
        if (type == 1) {
            int l, r; ll ppl; cin >> l >> r >> group[i] >> ppl;
            openCust[l].emplace_back(i, ppl);
            closeCust[r].emplace_back(i, ppl);
            tree.update(l, r, ppl, 1, 1, n);
        }
        else if (type == 2) {
            int l, r; ll cut; cin >> l >> r >> cut;
            vector<tt> updates;
            tree.breakDown(l, r, cut, 1, 1, n, updates);

            for (auto [l, r, w] : updates) {
                openCut[l].emplace_back(i, w);
                closeCut[r].emplace_back(i, w);
                tree.update(l, r, -w, 1, 1, n);
            }
        }
        else {
            int pos; ll ppl; cin >> pos >> ppl;
            query[pos].emplace_back(i, ppl);
        }
        ans[i] = -1;
    }

    for (int i = 1; i <= n; i++) {
        for (auto [crew, sz] : openCust[i])
            customer.update(crew, sz);
        for (auto [crew, sz] : openCut[i])
            cut.update(crew, sz);

        for (auto [moment, ppl] : query[i]) {
            ll curCustomer = customer.preSum(moment), leftCustomer = cut.preSum(moment);
            if (curCustomer - leftCustomer < ppl) ans[moment] = 0;
            else {
                int crew = customer.walk(leftCustomer + ppl) + 1;
                ans[moment] = group[crew];
            }
        }

        for (auto [crew, sz] : closeCust[i])
            customer.update(crew, -sz);
        for (auto [crew, sz] : closeCut[i])
            cut.update(crew, -sz);
    }

    for (int i = 1; i <= q; i++)
        if (ans[i] != -1) cout << ans[i] << "\n";

    return 0;
}

Compilation message

foodcourt.cpp: In member function 'void BIT::update(int, int)':
foodcourt.cpp:72:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for (; pos < tr.size(); pos += p(pos)) tr[pos] += val;
      |                ~~~~^~~~~~~~~~~
foodcourt.cpp: In member function 'int BIT::walk(ll)':
foodcourt.cpp:85:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |             if ((ans | msk) < tr.size() && tr[ans | msk] + sum < ub) ans |= msk, sum += tr[ans];
      |                 ~~~~~~~~~~~~^~~~~~~~~~~
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:113:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  113 |             for (auto [l, r, w] : updates) {
      |                       ^
foodcourt.cpp:127:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  127 |         for (auto [crew, sz] : openCust[i])
      |                   ^
foodcourt.cpp:129:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  129 |         for (auto [crew, sz] : openCut[i])
      |                   ^
foodcourt.cpp:132:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  132 |         for (auto [moment, ppl] : query[i]) {
      |                   ^
foodcourt.cpp:141:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  141 |         for (auto [crew, sz] : closeCust[i])
      |                   ^
foodcourt.cpp:143:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  143 |         for (auto [crew, sz] : closeCut[i])
      |                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 57424 KB Output is correct
2 Correct 24 ms 57436 KB Output is correct
3 Correct 23 ms 57344 KB Output is correct
4 Correct 25 ms 57176 KB Output is correct
5 Correct 23 ms 57272 KB Output is correct
6 Correct 23 ms 57176 KB Output is correct
7 Correct 24 ms 57436 KB Output is correct
8 Correct 24 ms 57308 KB Output is correct
9 Correct 24 ms 57432 KB Output is correct
10 Correct 25 ms 57404 KB Output is correct
11 Correct 24 ms 57260 KB Output is correct
12 Correct 25 ms 57436 KB Output is correct
13 Correct 23 ms 57180 KB Output is correct
14 Correct 24 ms 57332 KB Output is correct
15 Correct 24 ms 57176 KB Output is correct
16 Correct 27 ms 57436 KB Output is correct
17 Correct 29 ms 57436 KB Output is correct
18 Correct 28 ms 57432 KB Output is correct
19 Correct 31 ms 57340 KB Output is correct
20 Correct 30 ms 57372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 57424 KB Output is correct
2 Correct 24 ms 57436 KB Output is correct
3 Correct 23 ms 57344 KB Output is correct
4 Correct 25 ms 57176 KB Output is correct
5 Correct 23 ms 57272 KB Output is correct
6 Correct 23 ms 57176 KB Output is correct
7 Correct 24 ms 57436 KB Output is correct
8 Correct 24 ms 57308 KB Output is correct
9 Correct 24 ms 57432 KB Output is correct
10 Correct 25 ms 57404 KB Output is correct
11 Correct 24 ms 57260 KB Output is correct
12 Correct 25 ms 57436 KB Output is correct
13 Correct 23 ms 57180 KB Output is correct
14 Correct 24 ms 57332 KB Output is correct
15 Correct 24 ms 57176 KB Output is correct
16 Correct 27 ms 57436 KB Output is correct
17 Correct 29 ms 57436 KB Output is correct
18 Correct 28 ms 57432 KB Output is correct
19 Correct 31 ms 57340 KB Output is correct
20 Correct 30 ms 57372 KB Output is correct
21 Correct 36 ms 58968 KB Output is correct
22 Correct 32 ms 57936 KB Output is correct
23 Correct 31 ms 57168 KB Output is correct
24 Correct 28 ms 57428 KB Output is correct
25 Correct 26 ms 57176 KB Output is correct
26 Correct 27 ms 57168 KB Output is correct
27 Correct 28 ms 57436 KB Output is correct
28 Correct 27 ms 57436 KB Output is correct
29 Correct 30 ms 58428 KB Output is correct
30 Correct 26 ms 57424 KB Output is correct
31 Correct 34 ms 58832 KB Output is correct
32 Correct 44 ms 60244 KB Output is correct
33 Correct 41 ms 60756 KB Output is correct
34 Correct 30 ms 58300 KB Output is correct
35 Correct 27 ms 57688 KB Output is correct
36 Correct 55 ms 61520 KB Output is correct
37 Correct 26 ms 57432 KB Output is correct
38 Correct 30 ms 57436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 67152 KB Output is correct
2 Correct 155 ms 70736 KB Output is correct
3 Correct 154 ms 72272 KB Output is correct
4 Correct 153 ms 72276 KB Output is correct
5 Correct 211 ms 78672 KB Output is correct
6 Correct 239 ms 78420 KB Output is correct
7 Correct 39 ms 60032 KB Output is correct
8 Correct 43 ms 60544 KB Output is correct
9 Correct 109 ms 67368 KB Output is correct
10 Correct 120 ms 67964 KB Output is correct
11 Correct 121 ms 67820 KB Output is correct
12 Correct 122 ms 67924 KB Output is correct
13 Correct 102 ms 65184 KB Output is correct
14 Correct 112 ms 66132 KB Output is correct
15 Correct 166 ms 73556 KB Output is correct
16 Correct 189 ms 73844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1085 ms 236056 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 57424 KB Output is correct
2 Correct 24 ms 57436 KB Output is correct
3 Correct 23 ms 57344 KB Output is correct
4 Correct 25 ms 57176 KB Output is correct
5 Correct 23 ms 57272 KB Output is correct
6 Correct 23 ms 57176 KB Output is correct
7 Correct 24 ms 57436 KB Output is correct
8 Correct 24 ms 57308 KB Output is correct
9 Correct 24 ms 57432 KB Output is correct
10 Correct 25 ms 57404 KB Output is correct
11 Correct 24 ms 57260 KB Output is correct
12 Correct 25 ms 57436 KB Output is correct
13 Correct 23 ms 57180 KB Output is correct
14 Correct 24 ms 57332 KB Output is correct
15 Correct 24 ms 57176 KB Output is correct
16 Correct 27 ms 57436 KB Output is correct
17 Correct 29 ms 57436 KB Output is correct
18 Correct 28 ms 57432 KB Output is correct
19 Correct 31 ms 57340 KB Output is correct
20 Correct 30 ms 57372 KB Output is correct
21 Correct 113 ms 67152 KB Output is correct
22 Correct 155 ms 70736 KB Output is correct
23 Correct 154 ms 72272 KB Output is correct
24 Correct 153 ms 72276 KB Output is correct
25 Correct 211 ms 78672 KB Output is correct
26 Correct 239 ms 78420 KB Output is correct
27 Correct 39 ms 60032 KB Output is correct
28 Correct 43 ms 60544 KB Output is correct
29 Correct 109 ms 67368 KB Output is correct
30 Correct 120 ms 67964 KB Output is correct
31 Correct 121 ms 67820 KB Output is correct
32 Correct 122 ms 67924 KB Output is correct
33 Correct 102 ms 65184 KB Output is correct
34 Correct 112 ms 66132 KB Output is correct
35 Correct 166 ms 73556 KB Output is correct
36 Correct 189 ms 73844 KB Output is correct
37 Correct 123 ms 67400 KB Output is correct
38 Correct 77 ms 61264 KB Output is correct
39 Correct 38 ms 59832 KB Output is correct
40 Correct 51 ms 60328 KB Output is correct
41 Correct 116 ms 65104 KB Output is correct
42 Correct 110 ms 65108 KB Output is correct
43 Correct 157 ms 72248 KB Output is correct
44 Correct 138 ms 68768 KB Output is correct
45 Correct 122 ms 66036 KB Output is correct
46 Correct 151 ms 71864 KB Output is correct
47 Correct 46 ms 60600 KB Output is correct
48 Correct 115 ms 69780 KB Output is correct
49 Correct 171 ms 73792 KB Output is correct
50 Correct 199 ms 77904 KB Output is correct
51 Correct 234 ms 81340 KB Output is correct
52 Correct 235 ms 81724 KB Output is correct
53 Correct 113 ms 66640 KB Output is correct
54 Correct 139 ms 69204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 61136 KB Output is correct
2 Correct 76 ms 61348 KB Output is correct
3 Correct 76 ms 61520 KB Output is correct
4 Correct 61 ms 60240 KB Output is correct
5 Correct 68 ms 61012 KB Output is correct
6 Correct 78 ms 61520 KB Output is correct
7 Correct 45 ms 59836 KB Output is correct
8 Correct 42 ms 59988 KB Output is correct
9 Correct 56 ms 60868 KB Output is correct
10 Correct 56 ms 60064 KB Output is correct
11 Correct 67 ms 61012 KB Output is correct
12 Correct 70 ms 61008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 57424 KB Output is correct
2 Correct 24 ms 57436 KB Output is correct
3 Correct 23 ms 57344 KB Output is correct
4 Correct 25 ms 57176 KB Output is correct
5 Correct 23 ms 57272 KB Output is correct
6 Correct 23 ms 57176 KB Output is correct
7 Correct 24 ms 57436 KB Output is correct
8 Correct 24 ms 57308 KB Output is correct
9 Correct 24 ms 57432 KB Output is correct
10 Correct 25 ms 57404 KB Output is correct
11 Correct 24 ms 57260 KB Output is correct
12 Correct 25 ms 57436 KB Output is correct
13 Correct 23 ms 57180 KB Output is correct
14 Correct 24 ms 57332 KB Output is correct
15 Correct 24 ms 57176 KB Output is correct
16 Correct 27 ms 57436 KB Output is correct
17 Correct 29 ms 57436 KB Output is correct
18 Correct 28 ms 57432 KB Output is correct
19 Correct 31 ms 57340 KB Output is correct
20 Correct 30 ms 57372 KB Output is correct
21 Correct 36 ms 58968 KB Output is correct
22 Correct 32 ms 57936 KB Output is correct
23 Correct 31 ms 57168 KB Output is correct
24 Correct 28 ms 57428 KB Output is correct
25 Correct 26 ms 57176 KB Output is correct
26 Correct 27 ms 57168 KB Output is correct
27 Correct 28 ms 57436 KB Output is correct
28 Correct 27 ms 57436 KB Output is correct
29 Correct 30 ms 58428 KB Output is correct
30 Correct 26 ms 57424 KB Output is correct
31 Correct 34 ms 58832 KB Output is correct
32 Correct 44 ms 60244 KB Output is correct
33 Correct 41 ms 60756 KB Output is correct
34 Correct 30 ms 58300 KB Output is correct
35 Correct 27 ms 57688 KB Output is correct
36 Correct 55 ms 61520 KB Output is correct
37 Correct 26 ms 57432 KB Output is correct
38 Correct 30 ms 57436 KB Output is correct
39 Correct 113 ms 67152 KB Output is correct
40 Correct 155 ms 70736 KB Output is correct
41 Correct 154 ms 72272 KB Output is correct
42 Correct 153 ms 72276 KB Output is correct
43 Correct 211 ms 78672 KB Output is correct
44 Correct 239 ms 78420 KB Output is correct
45 Correct 39 ms 60032 KB Output is correct
46 Correct 43 ms 60544 KB Output is correct
47 Correct 109 ms 67368 KB Output is correct
48 Correct 120 ms 67964 KB Output is correct
49 Correct 121 ms 67820 KB Output is correct
50 Correct 122 ms 67924 KB Output is correct
51 Correct 102 ms 65184 KB Output is correct
52 Correct 112 ms 66132 KB Output is correct
53 Correct 166 ms 73556 KB Output is correct
54 Correct 189 ms 73844 KB Output is correct
55 Correct 123 ms 67400 KB Output is correct
56 Correct 77 ms 61264 KB Output is correct
57 Correct 38 ms 59832 KB Output is correct
58 Correct 51 ms 60328 KB Output is correct
59 Correct 116 ms 65104 KB Output is correct
60 Correct 110 ms 65108 KB Output is correct
61 Correct 157 ms 72248 KB Output is correct
62 Correct 138 ms 68768 KB Output is correct
63 Correct 122 ms 66036 KB Output is correct
64 Correct 151 ms 71864 KB Output is correct
65 Correct 46 ms 60600 KB Output is correct
66 Correct 115 ms 69780 KB Output is correct
67 Correct 171 ms 73792 KB Output is correct
68 Correct 199 ms 77904 KB Output is correct
69 Correct 234 ms 81340 KB Output is correct
70 Correct 235 ms 81724 KB Output is correct
71 Correct 113 ms 66640 KB Output is correct
72 Correct 139 ms 69204 KB Output is correct
73 Correct 71 ms 61136 KB Output is correct
74 Correct 76 ms 61348 KB Output is correct
75 Correct 76 ms 61520 KB Output is correct
76 Correct 61 ms 60240 KB Output is correct
77 Correct 68 ms 61012 KB Output is correct
78 Correct 78 ms 61520 KB Output is correct
79 Correct 45 ms 59836 KB Output is correct
80 Correct 42 ms 59988 KB Output is correct
81 Correct 56 ms 60868 KB Output is correct
82 Correct 56 ms 60064 KB Output is correct
83 Correct 67 ms 61012 KB Output is correct
84 Correct 70 ms 61008 KB Output is correct
85 Correct 971 ms 208668 KB Output is correct
86 Correct 556 ms 137316 KB Output is correct
87 Correct 87 ms 62288 KB Output is correct
88 Correct 90 ms 63056 KB Output is correct
89 Correct 119 ms 67444 KB Output is correct
90 Correct 113 ms 66432 KB Output is correct
91 Correct 403 ms 112568 KB Output is correct
92 Execution timed out 1068 ms 230864 KB Time limit exceeded
93 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 57424 KB Output is correct
2 Correct 24 ms 57436 KB Output is correct
3 Correct 23 ms 57344 KB Output is correct
4 Correct 25 ms 57176 KB Output is correct
5 Correct 23 ms 57272 KB Output is correct
6 Correct 23 ms 57176 KB Output is correct
7 Correct 24 ms 57436 KB Output is correct
8 Correct 24 ms 57308 KB Output is correct
9 Correct 24 ms 57432 KB Output is correct
10 Correct 25 ms 57404 KB Output is correct
11 Correct 24 ms 57260 KB Output is correct
12 Correct 25 ms 57436 KB Output is correct
13 Correct 23 ms 57180 KB Output is correct
14 Correct 24 ms 57332 KB Output is correct
15 Correct 24 ms 57176 KB Output is correct
16 Correct 27 ms 57436 KB Output is correct
17 Correct 29 ms 57436 KB Output is correct
18 Correct 28 ms 57432 KB Output is correct
19 Correct 31 ms 57340 KB Output is correct
20 Correct 30 ms 57372 KB Output is correct
21 Correct 36 ms 58968 KB Output is correct
22 Correct 32 ms 57936 KB Output is correct
23 Correct 31 ms 57168 KB Output is correct
24 Correct 28 ms 57428 KB Output is correct
25 Correct 26 ms 57176 KB Output is correct
26 Correct 27 ms 57168 KB Output is correct
27 Correct 28 ms 57436 KB Output is correct
28 Correct 27 ms 57436 KB Output is correct
29 Correct 30 ms 58428 KB Output is correct
30 Correct 26 ms 57424 KB Output is correct
31 Correct 34 ms 58832 KB Output is correct
32 Correct 44 ms 60244 KB Output is correct
33 Correct 41 ms 60756 KB Output is correct
34 Correct 30 ms 58300 KB Output is correct
35 Correct 27 ms 57688 KB Output is correct
36 Correct 55 ms 61520 KB Output is correct
37 Correct 26 ms 57432 KB Output is correct
38 Correct 30 ms 57436 KB Output is correct
39 Correct 113 ms 67152 KB Output is correct
40 Correct 155 ms 70736 KB Output is correct
41 Correct 154 ms 72272 KB Output is correct
42 Correct 153 ms 72276 KB Output is correct
43 Correct 211 ms 78672 KB Output is correct
44 Correct 239 ms 78420 KB Output is correct
45 Correct 39 ms 60032 KB Output is correct
46 Correct 43 ms 60544 KB Output is correct
47 Correct 109 ms 67368 KB Output is correct
48 Correct 120 ms 67964 KB Output is correct
49 Correct 121 ms 67820 KB Output is correct
50 Correct 122 ms 67924 KB Output is correct
51 Correct 102 ms 65184 KB Output is correct
52 Correct 112 ms 66132 KB Output is correct
53 Correct 166 ms 73556 KB Output is correct
54 Correct 189 ms 73844 KB Output is correct
55 Execution timed out 1085 ms 236056 KB Time limit exceeded
56 Halted 0 ms 0 KB -