Submission #1114007

#TimeUsernameProblemLanguageResultExecution timeMemory
1114007stdfloatBigger segments (IZhO19_segments)C++17
100 / 100
219 ms34632 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<ll> st; int fnd(int nd, int l, int r, int x, int y, ll vl) { if (r < x || y < l || vl < st[nd]) return -1; if (l == r) return l; int ch = nd << 1, md = (l + r) >> 1, res = fnd(ch + 1, md + 1, r, x, y, vl); return (~res ? res : fnd(ch, l, md, x, y, vl)); } ll upd(int nd, int l, int r, int x, ll vl) { if (r < x || x < l) return st[nd]; if (l == r) return st[nd] = vl; int ch = nd << 1, md = (l + r) >> 1; return st[nd] = min(upd(ch, l, md, x, vl), upd(ch + 1, md + 1, r, x, vl)); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n + 1); for (int i = 1; i <= n; i++) cin >> a[i]; vector<ll> p(n + 1); for (int i = 1; i <= n; i++) p[i] = p[i - 1] + a[i]; st.assign(n << 2, 0); vector<ll> dp(n + 1), v(n + 1); for (int i = 1; i <= n; i++) { int x = fnd(1, 0, n, 0, i - 1, p[i]); dp[i] = dp[x] + 1; upd(1, 0, n, i, (p[i] << 1) - p[x]); } cout << dp[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...