This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const ll inf = 1e18;
const int maxn = 5e5 + 10;
int n;
ll a[maxn];
ll pre[maxn];
ll dp[maxn];
int pos[maxn];
ll qry(int l, int r) {
assert(l<=r);
return pre[r]-pre[l-1];
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n;
for (int i=1; i<=n; i++) {
cin>>a[i];
}
for (int i=1; i<=n; i++) {
pre[i]=pre[i-1]+a[i];
}
for (int i=1; i<=n; i++) {
pos[i]=max(pos[i],pos[i-1]);
dp[i]=1+dp[pos[i]];
int lo=i;
int hi=n+1;
int p=-1;
while (hi-lo>1) {
int mid=(lo+hi)/2;
if (qry(pos[i]+1,i)<=qry(i+1,mid)) {
hi=mid;
p=mid;
} else {
lo=mid;
}
}
if (~p) {
pos[p]=i;
}
}
cout<<dp[n]<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |