Submission #382441

#TimeUsernameProblemLanguageResultExecution timeMemory
382441BartolMBigger segments (IZhO19_segments)C++17
100 / 100
121 ms18952 KiB
#include <bits/stdc++.h> using namespace std; #define X first #define Y second #define mp make_pair #define pb push_back typedef long long ll; typedef pair <int, int> pii; typedef pair <int, pii> pip; typedef pair <pii, int> ppi; typedef pair <ll, ll> pll; const int INF=0x3f3f3f3f; const ll MAX=(ll)INF*INF; const int N=5e5+5; int n; ll pref[N], p[N], dp[N]; int lef[N]; void solve() { pref[n+1]=MAX; lef[0]=0; dp[0]=0; for (int i=1; i<=n; ++i) { lef[i]=max(lef[i], lef[i-1]); dp[i]=dp[lef[i]]+1; ll br=2*pref[i]-pref[lef[i]]; int nx=lower_bound(pref, pref+n+2, br)-pref; lef[nx]=i; } printf("%lld\n", dp[n]); } void load() { scanf("%d", &n); for (int i=1; i<=n; ++i) { scanf("%lld", &p[i]); pref[i]=pref[i-1]+p[i]; } } int main() { load(); solve(); return 0; }

Compilation message (stderr)

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