#include <bits/stdc++.h>
#ifdef LOCAL
#include "/home/trcmai/code/tools.h"
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define debug(x...)
#endif
using namespace std;
#define all(a) a.begin(), a.end()
#define ll long long
#define endl '\n'
const int N = 1e6 + 6, LOG = 27, MOD = 1e9 + 7;
const ll INF = 1e18;
int n;
struct dynamic_segment_tree
{
struct node {ll v, l, r; node() {v = 0; l = -1, r = -1;}};
vector<node> st;
dynamic_segment_tree() {st.clear(); st.pb(node());};
void update(long long id, long long l, long long r, long long i, ll x)
{
if (l == r) {st[id].v = max(st[id].v,x); return;}
long long m = (r+l)>>1; st[id].v = max(st[id].v,x);
if (l <= i && i <= m)
{
if (st[id].l == -1) {st[id].l = st.size(); st.pb(node());}
update(st[id].l,l,m,i,x);
}
if (m < i && i <= r)
{
if (st[id].r == -1) {st[id].r = st.size(); st.pb(node());}
update(st[id].r,m+1,r,i,x);
}
}
ll get(long long id, long long l, long long r, long long u, long long v)
{
if (r < u || v < l) return 0;
if (u <= l && r <= v) return st[id].v;
long long m = (r+l)>>1; ll val = 0;
if (st[id].l != -1) val = max(val,get(st[id].l,l,m,u,v));
if (st[id].r != -1) val = max(val,get(st[id].r,m+1,r,u,v));
return val;
}
void update(long long i, ll x) {update(0,0,1e17,i,x);}
ll get(long long u, long long v) {return get(0,0,1e17,u,v);}
};
signed main() {
cin.tie(0)->sync_with_stdio(0);
auto solver=[&](){
cin>>n;
vector<ll>a(n + 1),dp(n + 1),opt(n + 1);
for(int i = 1;i <= n;++i){
cin>>a[i];
a[i] += a[i - 1];
}
dynamic_segment_tree st;
for(int i = 1;i <= n;++i){
int j = st.get(0,a[i]);
dp[i] = dp[j] + 1;
opt[i] = a[i] - a[j];
st.update(opt[i] + a[i],i);
}
cout<<dp[n]<<endl;
};
int t = 1; // cin>>t;
while (t--) solver();
}
Compilation message
segments.cpp: In constructor 'dynamic_segment_tree::dynamic_segment_tree()':
segments.cpp:20:44: error: 'class std::vector<dynamic_segment_tree::node>' has no member named 'pb'
20 | dynamic_segment_tree() {st.clear(); st.pb(node());};
| ^~
segments.cpp: In member function 'void dynamic_segment_tree::update(long long int, long long int, long long int, long long int, long long int)':
segments.cpp:27:59: error: 'class std::vector<dynamic_segment_tree::node>' has no member named 'pb'
27 | if (st[id].l == -1) {st[id].l = st.size(); st.pb(node());}
| ^~
segments.cpp:32:59: error: 'class std::vector<dynamic_segment_tree::node>' has no member named 'pb'
32 | if (st[id].r == -1) {st[id].r = st.size(); st.pb(node());}
| ^~