제출 #344659

#제출 시각아이디문제언어결과실행 시간메모리
344659NurlykhanBigger segments (IZhO19_segments)C++17
73 / 100
892 ms127768 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; 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; ll x; node() { l = r = -1; val = make_pair(0, 0); } }; node t[N * 10]; 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; upd(x, val, t[v].l, l, m); } else if (m + 1 <= x && x <= r) { if (t[v].r == -1) t[v].r = ++sz; 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; }

컴파일 시 표준 에러 (stderr) 메시지

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