Submission #146194

#TimeUsernameProblemLanguageResultExecution timeMemory
146194imeimi2000Bigger segments (IZhO19_segments)C++17
100 / 100
106 ms13048 KiB
#include <iostream> #include <algorithm> #include <vector> using namespace std; typedef long long llong; int n; llong S[500001]; int M[500002]; int D[500001]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> S[i]; S[i] += S[i - 1]; } for (int i = 1; i <= n; ++i) { M[i] = max(M[i], M[i - 1]); D[i] = D[M[i]] + 1; llong V = (S[i] << 1) - S[M[i]]; int s = i + 1, e = n + 1; while (s < e) { int m = (s + e) / 2; if (V <= S[m]) e = m; else s = m + 1; } M[s] = max(M[s], i); } printf("%d\n", D[n]); return 0; }
#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...