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;
#define int long long
const int N = 5e5 + 7;
int t[4 * N];
void upd(int v, int l, int r, int ind, int val){
if(r - l == 1)
t[v] = val;
else{
int mid = (l + r) / 2;
if(ind < mid){
upd(2 * v, l, mid, ind, val);
} else{
upd(2 * v + 1, mid, r, ind, val);
}
t[v] = min(t[2 * v], t[2 * v + 1]);
}
}
int get_ind(int v, int tl, int tr, int l, int r, int mx) {
if(tl >= r || tr <= l || t[v] > mx)
return -1;
if(tr - tl == 1)
return tl;
int tm = (tl + tr) / 2;
int ind = get_ind(2 * v + 1, tm, tr, l, r, mx);
if(ind == -1)
ind = get_ind(2 * v, tl, tm, l, r, mx);
return ind;
}
int n, a[N], pref[N], cnt[N], lst[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; ++i){
cin >> a[i];
pref[i + 1] = pref[i] + a[i];
}
for(int i = 1; i <= n; ++i){
int ind = get_ind(1, 0, n, 0, i, pref[i]);
cnt[i] = cnt[ind] + 1;
lst[i] = pref[i] - pref[ind];
upd(1, 0, n, i, lst[i] + pref[i]);
}
cout << cnt[n];
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... |