Submission #976894

#TimeUsernameProblemLanguageResultExecution timeMemory
976894zwezdinvFood Court (JOI21_foodcourt)C++17
0 / 100
412 ms52308 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 2.5e5 + 1; namespace ST { ll mn[4 * N], s_mn[4 * N], upd[4 * N], upd_mn[4 * N]; int cnt[4 * N]; void apply(int node, ll x) { mn[node] += x; s_mn[node] += x; upd_mn[node] += x; upd[node] += x; } void apply_mn(int node, ll x) { upd_mn[node] = max(upd_mn[node], x); mn[node] = max(mn[node], upd_mn[node]); } void push(int node) { apply(node << 1, upd[node]); apply(node << 1 | 1, upd[node]); apply_mn(node << 1, upd_mn[node]); apply_mn(node << 1 | 1, upd_mn[node]); upd[node] = 0; upd_mn[node] = -1e17; } void pull(int node) { mn[node] = min(mn[node << 1], mn[node << 1 | 1]); cnt[node] = 0; if (mn[node << 1] == mn[node]) cnt[node] += cnt[node << 1]; if (mn[node << 1 | 1] == mn[node]) cnt[node] += cnt[node << 1 | 1]; s_mn[node] = 1e17; for (auto x : {mn[node << 1], s_mn[node << 1], mn[node << 1 | 1], s_mn[node << 1 | 1]}) { if (x != mn[node]) s_mn[node] = min(s_mn[node], x); } } void update(int ql, int qr, int x, int node = 1, int l = 0, int r = N - 1) { if (r < ql || qr < l) return; if (ql <= l && r <= qr) { apply(node, x); return; } push(node); int m = (l + r) / 2; update(ql, qr, x, node << 1, l, m); update(ql, qr, x, node << 1 | 1, m + 1, r); pull(node); } void fix(int node = 1, int l = 0, int r = N - 1) { if (mn[node] >= 0) return; if (s_mn[node] > 0) { apply_mn(node, 0); return; } push(node); int m = (l + r) / 2; fix(node << 1, l, m); fix(node << 1 | 1, m + 1, r); pull(node); } ll get(int k, int node = 1, int l = 0, int r = N - 1) { if (l == r) return mn[node]; push(node); int m = (l + r) / 2; if (k <= m) return get(k, node << 1, l, m); else return get(k, node << 1 | 1, m + 1, r); } void build(int node = 1, int l = 0, int r = N - 1) { if (l == r) { mn[node] = 0; cnt[node] = 1; s_mn[node] = 1e17; upd[node] = 0; upd_mn[node] = -1e17; } else { int m = (l + r) / 2; build(node << 1, l, m); build(node << 1 | 1, m + 1, r); pull(node); } } } namespace ST2 { int tr[4 * N]; void update(int k, int x, int node = 1, int l = 0, int r = N - 1) { if (l == r) { tr[node] += x; return; } int m = (l + r) / 2; if (k <= m) update(k, x, node << 1, l, m); else update(k, x, node << 1 | 1, m + 1, r); tr[node] = tr[node << 1] + tr[node << 1 | 1]; } ll sm; int find_(int k, int node = 1, int l = 0, int r = N - 1) { if (l > k) return -1; if (r <= k) { if (tr[node] < sm) { sm -= tr[node]; return -1; } if (l == r) return l; } int m = (l + r) / 2; int res = find_(k, node << 1 | 1, m + 1, r); if (res == -1) return find_(k, node << 1, l, m); return res; } int find(int k, ll sm_) { sm = sm_; return find_(k); } } int col[N]; bool to_ans[N]; vector<pair<int, ll>> upd[N], ev[N]; int ans[N]; int main() { cin.tie(nullptr)->sync_with_stdio(0); ST::build(); int n, m, q; cin >> n >> m >> q; for (int i = 0; i < q; ++i) { int t; cin >> t; if (t == 1) { int l, r; ll b; cin >> l >> r >> col[i] >> b; --l, --r; ST::update(l, r, b); upd[l].emplace_back(i, b); upd[r + 1].emplace_back(i, -b); } else if (t == 2) { int l, r; ll k; cin >> l >> r >> k; --l, --r; ST::update(l, r, -k); ST::fix(); } else { int a; ll b; cin >> a >> b; --a; ev[a].emplace_back(i, ST::get(a) - b + 1); to_ans[i] = true; } } for (int i = 0; i < n; ++i) { for (auto [id, val] : upd[i]) { ST2::update(id, val); } for (auto [id, val] : ev[i]) { if (val <= 0) ans[id] = val; else { int k = ST2::find(id, val); ans[id] = col[k]; } } } for (int i = 0; i < q; ++i) { if (to_ans[i]) { cout << ans[i] << '\n'; } } }
#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...