Submission #1098085

#TimeUsernameProblemLanguageResultExecution timeMemory
1098085_callmelucianFood Court (JOI21_foodcourt)C++14
42 / 100
1085 ms236056 KiB
#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 (stderr)

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])
      |                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...