Submission #733457

#TimeUsernameProblemLanguageResultExecution timeMemory
733457tch1cherinSnowball (JOI21_ho_t2)C++17
100 / 100
239 ms14256 KiB
#include <bits/stdc++.h> using namespace std; template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; const long long INF = 1e18; int main() { int n, q; cin >> n >> q; vector<long long> X(n); for (auto &v : X) { cin >> v; } X.insert(X.begin(), -INF); X.insert(X.end(), INF); min_heap<pair<long long, int>> h; for (int i = 0; i <= n; i++) { h.push({X[i + 1] - X[i], i}); } long long L = 0, R = 0, x = 0; vector<long long> ans(n + 2); vector<bool> foundl(n + 2, false), foundr(n + 2, false); for (int i = 0; i < q; i++) { long long W; cin >> W; x += W; L = min(L, x); R = max(R, x); while (h.top().first <= R - L) { auto [d, j] = h.top(); h.pop(); long long left = R, right = -L; if (W > 0) left = d - right; if (W < 0) right = d - left; ans[j] += left; ans[j + 1] += right; foundr[j] = foundl[j + 1] = true; } } for (int i = 1; i <= n; i++) { if (!foundl[i]) ans[i] -= L; if (!foundr[i]) ans[i] += R; cout << ans[i] << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...