Submission #771752

#TimeUsernameProblemLanguageResultExecution timeMemory
771752JomnoiBigger segments (IZhO19_segments)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 5e5 + 5; long long A[MAX_N], pos[MAX_N], dp[MAX_N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N; cin >> N; for (int i = 1; i <= N; i++) { cin >> A[i]; A[i] += A[i - 1]; } for (int i = 1; i <= N; i++) { pos[i] = max(pos[i - 1], pos[i]); dp[i] = dp[pos[i]] + 1; int l = i + 1, r = N; while (l < r) { int mid = (l + r) / 2; if (A[mid] - A[i] >= A[i] - A[pos[i]]) r = mid; else l = mid + 1; } pos[l] = i; } cout << dp[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...