Submission #438620

#TimeUsernameProblemLanguageResultExecution timeMemory
438620jazzupBigger segments (IZhO19_segments)C++98
0 / 100
2 ms204 KiB
#include <bits/stdc++.h> #define long long long #define pii pair<long, long> #define x first #define y second using namespace std; const int N = 5e5 + 5; int n, dp[N]; long A[N], pref[N]; int main() { scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%lld", A + i); pref[i] = pref[i - 1] + A[i]; } set<pii, greater<pii> > S; S.emplace(0, 0); for(int i = 1; i <= n; i++) { auto it = S.lower_bound(pii(pref[i], 1e9)); dp[i] = dp[it->y] + 1; long val = 2ll * pref[i] - pref[it->y]; S.emplace(val, i); } printf("%d\n", dp[n]); return 0; }

Compilation message (stderr)

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