#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fr first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pw(x) (1ll << x)
#define sz(x) (int)((x).size())
#define pb push_back
#define endl '\n'
#define mp make_pair
#define vec vector
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef unsigned long long ull;
template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T>
using oset = tree<T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
struct st {
int n; vector <ll> t;
st (int n = 0) : n(n), t(4 * n, 1e18) {}
inline void upd (int v, int tl, int tr, int pos, ll x) {
if (tl == tr) { t[v] = x; return; }
int tm = (tl + tr) >> 1;
if (pos <= tm) upd(v << 1, tl, tm, pos, x);
else upd(v << 1 | 1, tm + 1, tr, pos, x);
t[v] = min(t[v << 1], t[v << 1 | 1]);
}
inline int get (int v, int tl, int tr, ll x) {
if (tl == tr) return tl;
int tm = (tl + tr) >> 1;
if (t[v << 1 | 1] <= x) return get(v << 1 | 1, tm + 1, tr, x);
else return get(v << 1, tl, tm, x);
}
inline ll getp (int v, int tl, int tr, int pos) {
if (tl == tr) return t[v];
int tm = (tl + tr) >> 1;
if (pos <= tm) return getp(v << 1, tl, tm, pos);
else return getp(v << 1 | 1, tm + 1, tr, pos);
}
inline void upd (int pos, ll x) { upd(1, 0, n - 1, pos, x); }
inline int get (ll x) { return get(1, 0, n - 1, x); }
inline ll getp (int i) { return getp(1, 0, n - 1, i); }
};
inline void solve () {
int n; cin >> n;
st s (n + 1); s.upd(0, 0);
ll sum = 0;
vector <int> dp (n + 1); dp[0] = 0;
vector <ll> pref (n + 1);
for (int i = 1; i <= n; ++i) {
int x; cin >> x; sum += x;
int p = s.get(sum);
dp[i] = dp[p] + 1; pref[i] = sum;
s.upd(i, sum * 2 - pref[p]);
}
cout << dp[n];
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1; // cin >> t;
while (t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
268 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
320 KB |
Output is correct |
26 |
Correct |
1 ms |
320 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
320 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
268 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
320 KB |
Output is correct |
26 |
Correct |
1 ms |
320 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
320 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
1 ms |
320 KB |
Output is correct |
31 |
Correct |
1 ms |
320 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
2 ms |
468 KB |
Output is correct |
35 |
Correct |
2 ms |
476 KB |
Output is correct |
36 |
Correct |
2 ms |
456 KB |
Output is correct |
37 |
Correct |
2 ms |
452 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
2 ms |
452 KB |
Output is correct |
40 |
Correct |
2 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
2 ms |
392 KB |
Output is correct |
43 |
Correct |
2 ms |
452 KB |
Output is correct |
44 |
Correct |
1 ms |
456 KB |
Output is correct |
45 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
268 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
320 KB |
Output is correct |
26 |
Correct |
1 ms |
320 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
320 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
1 ms |
320 KB |
Output is correct |
31 |
Correct |
1 ms |
320 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
2 ms |
468 KB |
Output is correct |
35 |
Correct |
2 ms |
476 KB |
Output is correct |
36 |
Correct |
2 ms |
456 KB |
Output is correct |
37 |
Correct |
2 ms |
452 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
2 ms |
452 KB |
Output is correct |
40 |
Correct |
2 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
2 ms |
392 KB |
Output is correct |
43 |
Correct |
2 ms |
452 KB |
Output is correct |
44 |
Correct |
1 ms |
456 KB |
Output is correct |
45 |
Correct |
1 ms |
460 KB |
Output is correct |
46 |
Correct |
19 ms |
4944 KB |
Output is correct |
47 |
Correct |
23 ms |
5068 KB |
Output is correct |
48 |
Correct |
21 ms |
5400 KB |
Output is correct |
49 |
Correct |
26 ms |
5516 KB |
Output is correct |
50 |
Correct |
25 ms |
5520 KB |
Output is correct |
51 |
Correct |
25 ms |
5588 KB |
Output is correct |
52 |
Correct |
12 ms |
2860 KB |
Output is correct |
53 |
Correct |
8 ms |
1868 KB |
Output is correct |
54 |
Correct |
19 ms |
4820 KB |
Output is correct |
55 |
Correct |
24 ms |
5524 KB |
Output is correct |
56 |
Correct |
21 ms |
5076 KB |
Output is correct |
57 |
Correct |
21 ms |
4948 KB |
Output is correct |
58 |
Correct |
20 ms |
5020 KB |
Output is correct |
59 |
Correct |
21 ms |
5204 KB |
Output is correct |
60 |
Correct |
24 ms |
5132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
268 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
320 KB |
Output is correct |
26 |
Correct |
1 ms |
320 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
320 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
1 ms |
320 KB |
Output is correct |
31 |
Correct |
1 ms |
320 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
2 ms |
468 KB |
Output is correct |
35 |
Correct |
2 ms |
476 KB |
Output is correct |
36 |
Correct |
2 ms |
456 KB |
Output is correct |
37 |
Correct |
2 ms |
452 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
2 ms |
452 KB |
Output is correct |
40 |
Correct |
2 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
2 ms |
392 KB |
Output is correct |
43 |
Correct |
2 ms |
452 KB |
Output is correct |
44 |
Correct |
1 ms |
456 KB |
Output is correct |
45 |
Correct |
1 ms |
460 KB |
Output is correct |
46 |
Correct |
19 ms |
4944 KB |
Output is correct |
47 |
Correct |
23 ms |
5068 KB |
Output is correct |
48 |
Correct |
21 ms |
5400 KB |
Output is correct |
49 |
Correct |
26 ms |
5516 KB |
Output is correct |
50 |
Correct |
25 ms |
5520 KB |
Output is correct |
51 |
Correct |
25 ms |
5588 KB |
Output is correct |
52 |
Correct |
12 ms |
2860 KB |
Output is correct |
53 |
Correct |
8 ms |
1868 KB |
Output is correct |
54 |
Correct |
19 ms |
4820 KB |
Output is correct |
55 |
Correct |
24 ms |
5524 KB |
Output is correct |
56 |
Correct |
21 ms |
5076 KB |
Output is correct |
57 |
Correct |
21 ms |
4948 KB |
Output is correct |
58 |
Correct |
20 ms |
5020 KB |
Output is correct |
59 |
Correct |
21 ms |
5204 KB |
Output is correct |
60 |
Correct |
24 ms |
5132 KB |
Output is correct |
61 |
Correct |
89 ms |
23756 KB |
Output is correct |
62 |
Correct |
98 ms |
23808 KB |
Output is correct |
63 |
Correct |
106 ms |
24136 KB |
Output is correct |
64 |
Correct |
114 ms |
26324 KB |
Output is correct |
65 |
Correct |
126 ms |
26700 KB |
Output is correct |
66 |
Correct |
125 ms |
26572 KB |
Output is correct |
67 |
Correct |
99 ms |
21372 KB |
Output is correct |
68 |
Correct |
49 ms |
10836 KB |
Output is correct |
69 |
Correct |
96 ms |
22988 KB |
Output is correct |
70 |
Correct |
129 ms |
26700 KB |
Output is correct |
71 |
Correct |
120 ms |
23756 KB |
Output is correct |
72 |
Correct |
101 ms |
24188 KB |
Output is correct |
73 |
Correct |
105 ms |
24780 KB |
Output is correct |
74 |
Correct |
108 ms |
25032 KB |
Output is correct |
75 |
Correct |
108 ms |
25164 KB |
Output is correct |