Submission #372740

#TimeUsernameProblemLanguageResultExecution timeMemory
372740SeDunionSnowball (JOI21_ho_t2)C++17
100 / 100
1102 ms8544 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e6 + 66; const ll INF = 1e18 + 123; ll L[N], R[N], x[N], shit[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n, q; cin >> n >> q; for (int i = 1 ; i <= n ; ++ i) cin >> x[i]; x[n + 1] = INF, x[0] = -INF; ll loc = 0; for (int i = 1 ; i <= q ; ++ i) { ll W; cin >> W; loc += W; L[i] = min(L[i - 1], loc); R[i] = max(R[i - 1], loc); } for (int i = 1 ; i <= n ; ++ i) { ll l = max(x[i - 1], x[i] + L[q]), r = x[i]; while (l < r) { ll m = (l + r) >> 1ll; int tl = 0, tr = q; while (tl < tr) { int tm = (tl + tr) >> 1; if (x[i] + L[tm] <= m) { tr = tm; } else { tl = tm + 1; } } if (x[i - 1] + R[tr] <= m) { r = m; } else { l = m + 1; } } //cerr << i << " " << x[i] << " L reach: " << r << "\n"; shit[i] += x[i] - r; } for (int i = 1 ; i <= n ; ++ i) { ll l = x[i], r = min(x[i + 1], x[i] + R[q]); while (l < r) { ll m = (l + r + 1) >> 1ll; int tl = 0, tr = q; while (tl < tr) { int tm = (tl + tr) >> 1; if (R[tm] + x[i] >= m) { tr = tm; } else { tl = tm + 1; } } if (x[i + 1] + L[tr] >= m) { l = m; } else { r = m - 1; } } //cerr << i << " " << x[i] << " R reach: " << l << "\n"; shit[i] += l - x[i]; } for (int i = 1 ; i <= n ; ++ i) { cout << shit[i] << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...