Submission #344644

#TimeUsernameProblemLanguageResultExecution timeMemory
344644NurlykhanBigger segments (IZhO19_segments)C++17
13 / 100
2 ms620 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = (int)5e5 + 10; const int mod = (int)1e9 + 7; 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]; unordered_map<int, pair<int, int> > t; pair<int, int> get(ll x) { assert(x >= 0); pair<int, int> ans = make_pair(0, 0); while (x >= 0) { if (t.count(x)) ans = max(ans, t[x]); x &= x + 1; x--; } return ans; } void upd(ll x, pair<int, int> y) { assert(x >= 0); while (x < (ll)1e15) { t[x] = max(t[x], y); x |= x + 1; } } 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:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
segments.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |         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...