Submission #880146

#TimeUsernameProblemLanguageResultExecution timeMemory
880146rockstarSnowball (JOI21_ho_t2)C++17
100 / 100
2058 ms14000 KiB
//#pragma GCC optimize("O3,unroll-loops,inline") #include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll #define all(a) a.begin(), a.end() bool check_right(int i, int len, vector<int>& mn, vector<int>& mx, int dist_to_next) { int q = mx.size() - 1; int l = -1, r = q; while (r - l > 1) { int mid = (l + r) / 2; if (mx[mid] >= len) r = mid; else l = mid; } return mx[r] >= len && dist_to_next + mn[r] - len >= 0; } bool check_left(int i, int len, vector<int>& mn, vector<int>& mx, int dist_to_next) { int q = mx.size() - 1; int l = -1, r = q; while (r - l > 1) { int mid = (l + r) / 2; if (-mn[mid] >= len) r = mid; else l = mid; } return -mn[r] >= len && dist_to_next - mx[r] - len >= 0; } void solve() { int n, q; cin >> n >> q; vector<int> x(n); for (int& i : x) cin >> i; vector<int> ans(n, 0), mn(q + 1, 0), mx(q + 1, 0); int a = 0; for (int i = 0; i < q; ++i) { int w; cin >> w; a += w; mn[i + 1] = min(mn[i], a); mx[i + 1] = max(mx[i], a); } for (int i = 0; i < n; ++i) { int l = 0, r = 1e18; while (r - l > 1) { int mid = r / 2 + l / 2 + (r % 2 + l % 2) / 2; if (check_right(i, mid, mn, mx, (i != n - 1 ? x[i + 1] - x[i] : 1e18))) l = mid; else r = mid; } ans[i] += l; l = 0, r = 1e18; while (r - l > 1) { int mid = r / 2 + l / 2 + (r % 2 + l % 2) / 2; if (check_left(i, mid, mn, mx, (i != 0 ? x[i] - x[i - 1] : 1e18))) l = mid; else r = mid; } ans[i] += l; } for (int i : ans) cout << i << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; while (t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...