Submission #701649

#TimeUsernameProblemLanguageResultExecution timeMemory
701649lto5Bigger segments (IZhO19_segments)C++14
100 / 100
79 ms18816 KiB
#include <bits/stdc++.h> using namespace std; using TNode = pair<int, int64_t>; int a[500005]; int64_t s[500005]; TNode f[500005]; int64_t get(int l, int r) { return s[r] - s[l - 1]; } TNode better(TNode a, TNode b) { if (a.first != b.first) { return a.first > b.first ? a : b; } return a.second < b.second ? a : b; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "a" if (fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; s[i] = s[i - 1] + a[i]; } for (int i = 0; i <= n; i++) { f[i] = {0, 1e18}; } f[1] = {1, a[1]}; for (int i = 1; i <= n; i++) { if (f[i].first == 0) { continue; } f[i + 1] = better(f[i + 1], {f[i].first, f[i].second + a[i + 1]}); int lo = i + 1, hi = n; int pos = -1; while (lo <= hi) { int mid = (lo + hi) / 2; if (get(i + 1, mid) >= f[i].second) { pos = mid; hi = mid - 1; } else { lo = mid + 1; } } if (pos != -1) { f[pos] = better(f[pos], {f[i].first + 1, get(i + 1, pos)}); } } int best = 0; for (int i = 1; i <= n; i++) { best = max(best, f[i].first); } cout << best; return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen(task ".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     freopen(task ".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...