#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pf push_front
#define fi first
#define se second
const ll mod = 1e9+7, mxn = 3007;
ll a[mxn];
struct dynamic_segment_tree
{
struct node {ll v, l, r; node() {v = -1e9; l = -1, r = -1;}};
vector<node> st;
dynamic_segment_tree() {st.clear(); st.pb(node());};
void update(ll id, ll l, ll r, ll i, ll x)
{
if (l == r) {st[id].v = max(st[id].v,x); return;}
ll 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(ll id, ll l, ll r, ll u, ll v)
{
if (r < u || v < l) return -1e9;
if (u <= l && r <= v) return st[id].v;
ll m = (r+l)>>1, val = -1e9;
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(ll i, ll x) {update(0,0,1e16,i,x);}
ll get(ll u, ll v) {return get(0,0,1e16,u,v);}
};
vector<dynamic_segment_tree> st(mxn);
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
ll n; cin >> n;
for (ll i = 1; i <= n; i++)
{
cin >> a[i];
a[i] += a[i-1];
}
ll ans = 0;
st[0].update(0,0);
for (ll i = 1; i <= n; i++)
{
for (ll j = 1; j <= i; j++)
{
ll sum = a[i]-a[j-1];
ll opt = st[j-1].get(0,sum)+1;
// cerr << j << ' ' << i << ' ' << opt << '\n';
st[i].update(sum,opt);
ans = max(ans, opt);
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
652 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
544 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
652 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
544 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
81 ms |
44112 KB |
Output is correct |
17 |
Correct |
94 ms |
70800 KB |
Output is correct |
18 |
Correct |
97 ms |
85040 KB |
Output is correct |
19 |
Correct |
106 ms |
86356 KB |
Output is correct |
20 |
Correct |
113 ms |
87604 KB |
Output is correct |
21 |
Correct |
118 ms |
91596 KB |
Output is correct |
22 |
Correct |
63 ms |
59564 KB |
Output is correct |
23 |
Correct |
34 ms |
34252 KB |
Output is correct |
24 |
Correct |
50 ms |
13952 KB |
Output is correct |
25 |
Correct |
116 ms |
95920 KB |
Output is correct |
26 |
Correct |
42 ms |
9556 KB |
Output is correct |
27 |
Correct |
56 ms |
17236 KB |
Output is correct |
28 |
Correct |
43 ms |
8776 KB |
Output is correct |
29 |
Correct |
56 ms |
28756 KB |
Output is correct |
30 |
Correct |
58 ms |
31828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
652 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
544 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
81 ms |
44112 KB |
Output is correct |
17 |
Correct |
94 ms |
70800 KB |
Output is correct |
18 |
Correct |
97 ms |
85040 KB |
Output is correct |
19 |
Correct |
106 ms |
86356 KB |
Output is correct |
20 |
Correct |
113 ms |
87604 KB |
Output is correct |
21 |
Correct |
118 ms |
91596 KB |
Output is correct |
22 |
Correct |
63 ms |
59564 KB |
Output is correct |
23 |
Correct |
34 ms |
34252 KB |
Output is correct |
24 |
Correct |
50 ms |
13952 KB |
Output is correct |
25 |
Correct |
116 ms |
95920 KB |
Output is correct |
26 |
Correct |
42 ms |
9556 KB |
Output is correct |
27 |
Correct |
56 ms |
17236 KB |
Output is correct |
28 |
Correct |
43 ms |
8776 KB |
Output is correct |
29 |
Correct |
56 ms |
28756 KB |
Output is correct |
30 |
Correct |
58 ms |
31828 KB |
Output is correct |
31 |
Runtime error |
552 ms |
262144 KB |
Execution killed with signal 9 |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
652 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
544 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
81 ms |
44112 KB |
Output is correct |
17 |
Correct |
94 ms |
70800 KB |
Output is correct |
18 |
Correct |
97 ms |
85040 KB |
Output is correct |
19 |
Correct |
106 ms |
86356 KB |
Output is correct |
20 |
Correct |
113 ms |
87604 KB |
Output is correct |
21 |
Correct |
118 ms |
91596 KB |
Output is correct |
22 |
Correct |
63 ms |
59564 KB |
Output is correct |
23 |
Correct |
34 ms |
34252 KB |
Output is correct |
24 |
Correct |
50 ms |
13952 KB |
Output is correct |
25 |
Correct |
116 ms |
95920 KB |
Output is correct |
26 |
Correct |
42 ms |
9556 KB |
Output is correct |
27 |
Correct |
56 ms |
17236 KB |
Output is correct |
28 |
Correct |
43 ms |
8776 KB |
Output is correct |
29 |
Correct |
56 ms |
28756 KB |
Output is correct |
30 |
Correct |
58 ms |
31828 KB |
Output is correct |
31 |
Runtime error |
552 ms |
262144 KB |
Execution killed with signal 9 |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
652 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
544 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
81 ms |
44112 KB |
Output is correct |
17 |
Correct |
94 ms |
70800 KB |
Output is correct |
18 |
Correct |
97 ms |
85040 KB |
Output is correct |
19 |
Correct |
106 ms |
86356 KB |
Output is correct |
20 |
Correct |
113 ms |
87604 KB |
Output is correct |
21 |
Correct |
118 ms |
91596 KB |
Output is correct |
22 |
Correct |
63 ms |
59564 KB |
Output is correct |
23 |
Correct |
34 ms |
34252 KB |
Output is correct |
24 |
Correct |
50 ms |
13952 KB |
Output is correct |
25 |
Correct |
116 ms |
95920 KB |
Output is correct |
26 |
Correct |
42 ms |
9556 KB |
Output is correct |
27 |
Correct |
56 ms |
17236 KB |
Output is correct |
28 |
Correct |
43 ms |
8776 KB |
Output is correct |
29 |
Correct |
56 ms |
28756 KB |
Output is correct |
30 |
Correct |
58 ms |
31828 KB |
Output is correct |
31 |
Runtime error |
552 ms |
262144 KB |
Execution killed with signal 9 |
32 |
Halted |
0 ms |
0 KB |
- |