Submission #715327

#TimeUsernameProblemLanguageResultExecution timeMemory
715327PringSnowball (JOI21_ho_t2)C++14
100 / 100
135 ms17044 KiB
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> pii; const int MXN = 200005; int n, q, pos[MXN], w0[MXN], ans[MXN], bound; vector<int> w; vector<pii> vp; void BUILD_W() { int l = 0, r = 0, now = 0; for (int i = 0; i < q; i++) { now += w0[i]; if (r < now) { r = now; w.push_back(now); } else if (now < l) { l = now; w.push_back(now); } } q = w.size(); now = 0; l = 0; r = 0; vp.push_back({0, 0}); for (int i = 0; i < q; i++) { now = w[i]; l = min(now, l); r = max(now, r); vp.push_back({r, -l}); } bound = vp.back().first + vp.back().second; } pii BSH(int x) { if (x >= bound) return vp.back(); int l = 0, r = q + 1; while (l + 1 < r) { int mid = (l + r) >> 1; (vp[mid].first + vp[mid].second > x ? r : l) = mid; } int d = x - vp[l].first - vp[l].second; pii ans = vp[l]; if (vp[l].first != vp[l + 1].first) ans.first += d; else ans.second += d; return ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> q; for (int i = 0; i < n; i++) cin >> pos[i]; for (int i = 0; i < q; i++) cin >> w0[i]; BUILD_W(); // for (auto &i : w) cout << i << ' '; // cout << endl; // for (auto &i : vp) cout << i.first << ' ' << i.second << endl; for (int i = 0; i + 1 < n; i++) { pii p = BSH(pos[i + 1] - pos[i]); ans[i] += p.first; ans[i + 1] += p.second; } ans[0] += vp.back().second; ans[n - 1] += vp.back().first; for (int i = 0; i < n; i++) cout << ans[i] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...