Submission #344667

#TimeUsernameProblemLanguageResultExecution timeMemory
344667NurlykhanBigger segments (IZhO19_segments)C++17
73 / 100
973 ms262144 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = (int)5e5 + 10; const int mod = (int)1e9 + 7; const ll inf = (ll) 1e16 + 10; int n; int a[N]; ll pref[N]; ll get_sum(int l, int r) { return pref[r] - pref[l - 1]; } pair<int, int> dp[N]; struct node { int l, r; pair<int, int> val; node() { l = r = -1; val = make_pair(0, 0); } }; node t[N * 20]; int sz = 1; void upd(ll x, pair<int, int> val, int v = 1, ll l = 0, ll r = inf) { if (l == r) { t[v].val = max(t[v].val, val); return; } ll m = (l + r) / 2; if (l <= x && x <= m) { if (t[v].l == -1) t[v].l = ++sz; assert(sz < 20 * N); upd(x, val, t[v].l, l, m); } else if (m + 1 <= x && x <= r) { if (t[v].r == -1) t[v].r = ++sz; assert(sz < 20 * N); upd(x, val, t[v].r, m + 1, r); } t[v].val = make_pair(0, 0); if (t[v].l != -1) t[v].val = max(t[v].val, t[t[v].l].val); if (t[v].r != -1) t[v].val = max(t[v].val, t[t[v].r].val); } pair<int, int> get(ll x, int v = 1, ll l = 0, ll r = inf) { if (l > x) return make_pair(0, 0); // cout << v << ' ' << l << ' ' << r << ' ' << x << endl; if (r <= x) return t[v].val; pair<int, int> ans = make_pair(0, 0); ll m = (l + r) / 2; if (t[v].l != -1) ans = max(ans, get(x, t[v].l, l, m)); if (t[v].r != -1) ans = max(ans, get(x, t[v].r, m + 1, r)); return ans; } int main() { // freopen("in.txt", "r", stdin); scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); pref[i] = pref[i - 1] + a[i]; } for (int i = 1; i <= n; i++) { dp[i] = make_pair(1, 1); dp[i] = max(dp[i], get(pref[i])); upd(2 * pref[i] - pref[dp[i].second - 1], make_pair(dp[i].first + 1, i + 1)); } cout << dp[n].first; return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   73 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
segments.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   75 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
#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...