#include <bits/stdc++.h>
#include <ext/rope>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#define file ""
#define all(x) x.begin(), x.end()
#define sc second
#define fr first
#define pb push_back
#define mp make_pair
#define pss pair<line*, line*>
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const ll inf = 1e18;
const int MOD = 1e9 + 7;
const int dx[] = {+1, -1, 0, 0};
const int dy[] = {0, 0, +1, -1};
int const N = 7e6;
vector<int> L, R;
vector<pii> t;
int cnt = 1;
void update (int u, ll l, ll r, ll pos, pll val) {
if(l > r) return;
if (l == r) {
t[u] = val;
return;
}
ll m = (l + r) / 2;
if (pos <= m) {
if (!L[u]) L[u] = ++cnt;
update (L[u], l, m, pos, val);
}
else {
if (!R[u]) R[u] = ++cnt;
update (R[u], m + 1, r, pos, val);
}
t[u] = max(t[L[u]], t[R[u]]);
}
pii get (int u, ll ul, ll ur, ll l, ll r) {
if (!u || l > r || ul > ur || l > ur || ul > r)
return {0, 0};
if (l <= ul && ur <= r)
return t[u];
ll um = (ul + ur) / 2;
return max(get(L[u], ul, um, l, r), get(R[u], um + 1, ur, l, r));
}
int main() {
#ifdef Mask
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n + 1);
L.resize(N);
R = L;
t.resize(N);
for (int i = 1; i <= n; i++)
cin >> a[i];
vector<ll> dp(n + 1), sum(n + 1), pref(n + 1);
for (int i = 1; i <= n; i++)
pref[i] = pref[i - 1] + a[i];
for (int i = 1; i <= n; i++) {
pii k = get(1, 1, inf, 1, pref[i]);
dp[i] = k.fr + 1;
sum[i] = pref[i] - pref[k.sc];
update (1, 1, inf, sum[i] + pref[i], {dp[i], i});
}
cout << dp[n];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
110072 KB |
Output is correct |
2 |
Correct |
59 ms |
109944 KB |
Output is correct |
3 |
Correct |
61 ms |
109948 KB |
Output is correct |
4 |
Correct |
61 ms |
109940 KB |
Output is correct |
5 |
Correct |
59 ms |
109872 KB |
Output is correct |
6 |
Correct |
60 ms |
109944 KB |
Output is correct |
7 |
Correct |
59 ms |
109944 KB |
Output is correct |
8 |
Correct |
59 ms |
109912 KB |
Output is correct |
9 |
Correct |
59 ms |
109944 KB |
Output is correct |
10 |
Correct |
67 ms |
109944 KB |
Output is correct |
11 |
Correct |
59 ms |
109944 KB |
Output is correct |
12 |
Correct |
59 ms |
109944 KB |
Output is correct |
13 |
Correct |
60 ms |
109944 KB |
Output is correct |
14 |
Correct |
59 ms |
109944 KB |
Output is correct |
15 |
Correct |
61 ms |
109944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
110072 KB |
Output is correct |
2 |
Correct |
59 ms |
109944 KB |
Output is correct |
3 |
Correct |
61 ms |
109948 KB |
Output is correct |
4 |
Correct |
61 ms |
109940 KB |
Output is correct |
5 |
Correct |
59 ms |
109872 KB |
Output is correct |
6 |
Correct |
60 ms |
109944 KB |
Output is correct |
7 |
Correct |
59 ms |
109944 KB |
Output is correct |
8 |
Correct |
59 ms |
109912 KB |
Output is correct |
9 |
Correct |
59 ms |
109944 KB |
Output is correct |
10 |
Correct |
67 ms |
109944 KB |
Output is correct |
11 |
Correct |
59 ms |
109944 KB |
Output is correct |
12 |
Correct |
59 ms |
109944 KB |
Output is correct |
13 |
Correct |
60 ms |
109944 KB |
Output is correct |
14 |
Correct |
59 ms |
109944 KB |
Output is correct |
15 |
Correct |
61 ms |
109944 KB |
Output is correct |
16 |
Correct |
60 ms |
109944 KB |
Output is correct |
17 |
Correct |
60 ms |
109944 KB |
Output is correct |
18 |
Correct |
61 ms |
109944 KB |
Output is correct |
19 |
Correct |
60 ms |
109944 KB |
Output is correct |
20 |
Correct |
60 ms |
109944 KB |
Output is correct |
21 |
Correct |
60 ms |
109944 KB |
Output is correct |
22 |
Correct |
60 ms |
109944 KB |
Output is correct |
23 |
Correct |
60 ms |
110072 KB |
Output is correct |
24 |
Correct |
59 ms |
109944 KB |
Output is correct |
25 |
Correct |
60 ms |
109948 KB |
Output is correct |
26 |
Correct |
60 ms |
109944 KB |
Output is correct |
27 |
Correct |
59 ms |
109944 KB |
Output is correct |
28 |
Correct |
60 ms |
109944 KB |
Output is correct |
29 |
Correct |
60 ms |
109944 KB |
Output is correct |
30 |
Correct |
59 ms |
109944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
110072 KB |
Output is correct |
2 |
Correct |
59 ms |
109944 KB |
Output is correct |
3 |
Correct |
61 ms |
109948 KB |
Output is correct |
4 |
Correct |
61 ms |
109940 KB |
Output is correct |
5 |
Correct |
59 ms |
109872 KB |
Output is correct |
6 |
Correct |
60 ms |
109944 KB |
Output is correct |
7 |
Correct |
59 ms |
109944 KB |
Output is correct |
8 |
Correct |
59 ms |
109912 KB |
Output is correct |
9 |
Correct |
59 ms |
109944 KB |
Output is correct |
10 |
Correct |
67 ms |
109944 KB |
Output is correct |
11 |
Correct |
59 ms |
109944 KB |
Output is correct |
12 |
Correct |
59 ms |
109944 KB |
Output is correct |
13 |
Correct |
60 ms |
109944 KB |
Output is correct |
14 |
Correct |
59 ms |
109944 KB |
Output is correct |
15 |
Correct |
61 ms |
109944 KB |
Output is correct |
16 |
Correct |
60 ms |
109944 KB |
Output is correct |
17 |
Correct |
60 ms |
109944 KB |
Output is correct |
18 |
Correct |
61 ms |
109944 KB |
Output is correct |
19 |
Correct |
60 ms |
109944 KB |
Output is correct |
20 |
Correct |
60 ms |
109944 KB |
Output is correct |
21 |
Correct |
60 ms |
109944 KB |
Output is correct |
22 |
Correct |
60 ms |
109944 KB |
Output is correct |
23 |
Correct |
60 ms |
110072 KB |
Output is correct |
24 |
Correct |
59 ms |
109944 KB |
Output is correct |
25 |
Correct |
60 ms |
109948 KB |
Output is correct |
26 |
Correct |
60 ms |
109944 KB |
Output is correct |
27 |
Correct |
59 ms |
109944 KB |
Output is correct |
28 |
Correct |
60 ms |
109944 KB |
Output is correct |
29 |
Correct |
60 ms |
109944 KB |
Output is correct |
30 |
Correct |
59 ms |
109944 KB |
Output is correct |
31 |
Correct |
67 ms |
109944 KB |
Output is correct |
32 |
Correct |
64 ms |
110076 KB |
Output is correct |
33 |
Correct |
63 ms |
109944 KB |
Output is correct |
34 |
Correct |
66 ms |
109944 KB |
Output is correct |
35 |
Correct |
76 ms |
110076 KB |
Output is correct |
36 |
Correct |
63 ms |
109944 KB |
Output is correct |
37 |
Correct |
63 ms |
109944 KB |
Output is correct |
38 |
Correct |
62 ms |
109948 KB |
Output is correct |
39 |
Correct |
63 ms |
109948 KB |
Output is correct |
40 |
Correct |
68 ms |
110072 KB |
Output is correct |
41 |
Correct |
62 ms |
110072 KB |
Output is correct |
42 |
Correct |
62 ms |
109944 KB |
Output is correct |
43 |
Correct |
63 ms |
109944 KB |
Output is correct |
44 |
Correct |
63 ms |
110076 KB |
Output is correct |
45 |
Correct |
64 ms |
110072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
110072 KB |
Output is correct |
2 |
Correct |
59 ms |
109944 KB |
Output is correct |
3 |
Correct |
61 ms |
109948 KB |
Output is correct |
4 |
Correct |
61 ms |
109940 KB |
Output is correct |
5 |
Correct |
59 ms |
109872 KB |
Output is correct |
6 |
Correct |
60 ms |
109944 KB |
Output is correct |
7 |
Correct |
59 ms |
109944 KB |
Output is correct |
8 |
Correct |
59 ms |
109912 KB |
Output is correct |
9 |
Correct |
59 ms |
109944 KB |
Output is correct |
10 |
Correct |
67 ms |
109944 KB |
Output is correct |
11 |
Correct |
59 ms |
109944 KB |
Output is correct |
12 |
Correct |
59 ms |
109944 KB |
Output is correct |
13 |
Correct |
60 ms |
109944 KB |
Output is correct |
14 |
Correct |
59 ms |
109944 KB |
Output is correct |
15 |
Correct |
61 ms |
109944 KB |
Output is correct |
16 |
Correct |
60 ms |
109944 KB |
Output is correct |
17 |
Correct |
60 ms |
109944 KB |
Output is correct |
18 |
Correct |
61 ms |
109944 KB |
Output is correct |
19 |
Correct |
60 ms |
109944 KB |
Output is correct |
20 |
Correct |
60 ms |
109944 KB |
Output is correct |
21 |
Correct |
60 ms |
109944 KB |
Output is correct |
22 |
Correct |
60 ms |
109944 KB |
Output is correct |
23 |
Correct |
60 ms |
110072 KB |
Output is correct |
24 |
Correct |
59 ms |
109944 KB |
Output is correct |
25 |
Correct |
60 ms |
109948 KB |
Output is correct |
26 |
Correct |
60 ms |
109944 KB |
Output is correct |
27 |
Correct |
59 ms |
109944 KB |
Output is correct |
28 |
Correct |
60 ms |
109944 KB |
Output is correct |
29 |
Correct |
60 ms |
109944 KB |
Output is correct |
30 |
Correct |
59 ms |
109944 KB |
Output is correct |
31 |
Correct |
67 ms |
109944 KB |
Output is correct |
32 |
Correct |
64 ms |
110076 KB |
Output is correct |
33 |
Correct |
63 ms |
109944 KB |
Output is correct |
34 |
Correct |
66 ms |
109944 KB |
Output is correct |
35 |
Correct |
76 ms |
110076 KB |
Output is correct |
36 |
Correct |
63 ms |
109944 KB |
Output is correct |
37 |
Correct |
63 ms |
109944 KB |
Output is correct |
38 |
Correct |
62 ms |
109948 KB |
Output is correct |
39 |
Correct |
63 ms |
109948 KB |
Output is correct |
40 |
Correct |
68 ms |
110072 KB |
Output is correct |
41 |
Correct |
62 ms |
110072 KB |
Output is correct |
42 |
Correct |
62 ms |
109944 KB |
Output is correct |
43 |
Correct |
63 ms |
109944 KB |
Output is correct |
44 |
Correct |
63 ms |
110076 KB |
Output is correct |
45 |
Correct |
64 ms |
110072 KB |
Output is correct |
46 |
Correct |
163 ms |
112764 KB |
Output is correct |
47 |
Correct |
192 ms |
112632 KB |
Output is correct |
48 |
Correct |
199 ms |
112640 KB |
Output is correct |
49 |
Correct |
211 ms |
112760 KB |
Output is correct |
50 |
Correct |
239 ms |
112632 KB |
Output is correct |
51 |
Correct |
189 ms |
112632 KB |
Output is correct |
52 |
Correct |
130 ms |
111352 KB |
Output is correct |
53 |
Correct |
99 ms |
110712 KB |
Output is correct |
54 |
Correct |
193 ms |
112632 KB |
Output is correct |
55 |
Correct |
220 ms |
112632 KB |
Output is correct |
56 |
Correct |
210 ms |
112840 KB |
Output is correct |
57 |
Correct |
192 ms |
112632 KB |
Output is correct |
58 |
Correct |
207 ms |
112636 KB |
Output is correct |
59 |
Correct |
226 ms |
112760 KB |
Output is correct |
60 |
Correct |
207 ms |
112632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
110072 KB |
Output is correct |
2 |
Correct |
59 ms |
109944 KB |
Output is correct |
3 |
Correct |
61 ms |
109948 KB |
Output is correct |
4 |
Correct |
61 ms |
109940 KB |
Output is correct |
5 |
Correct |
59 ms |
109872 KB |
Output is correct |
6 |
Correct |
60 ms |
109944 KB |
Output is correct |
7 |
Correct |
59 ms |
109944 KB |
Output is correct |
8 |
Correct |
59 ms |
109912 KB |
Output is correct |
9 |
Correct |
59 ms |
109944 KB |
Output is correct |
10 |
Correct |
67 ms |
109944 KB |
Output is correct |
11 |
Correct |
59 ms |
109944 KB |
Output is correct |
12 |
Correct |
59 ms |
109944 KB |
Output is correct |
13 |
Correct |
60 ms |
109944 KB |
Output is correct |
14 |
Correct |
59 ms |
109944 KB |
Output is correct |
15 |
Correct |
61 ms |
109944 KB |
Output is correct |
16 |
Correct |
60 ms |
109944 KB |
Output is correct |
17 |
Correct |
60 ms |
109944 KB |
Output is correct |
18 |
Correct |
61 ms |
109944 KB |
Output is correct |
19 |
Correct |
60 ms |
109944 KB |
Output is correct |
20 |
Correct |
60 ms |
109944 KB |
Output is correct |
21 |
Correct |
60 ms |
109944 KB |
Output is correct |
22 |
Correct |
60 ms |
109944 KB |
Output is correct |
23 |
Correct |
60 ms |
110072 KB |
Output is correct |
24 |
Correct |
59 ms |
109944 KB |
Output is correct |
25 |
Correct |
60 ms |
109948 KB |
Output is correct |
26 |
Correct |
60 ms |
109944 KB |
Output is correct |
27 |
Correct |
59 ms |
109944 KB |
Output is correct |
28 |
Correct |
60 ms |
109944 KB |
Output is correct |
29 |
Correct |
60 ms |
109944 KB |
Output is correct |
30 |
Correct |
59 ms |
109944 KB |
Output is correct |
31 |
Correct |
67 ms |
109944 KB |
Output is correct |
32 |
Correct |
64 ms |
110076 KB |
Output is correct |
33 |
Correct |
63 ms |
109944 KB |
Output is correct |
34 |
Correct |
66 ms |
109944 KB |
Output is correct |
35 |
Correct |
76 ms |
110076 KB |
Output is correct |
36 |
Correct |
63 ms |
109944 KB |
Output is correct |
37 |
Correct |
63 ms |
109944 KB |
Output is correct |
38 |
Correct |
62 ms |
109948 KB |
Output is correct |
39 |
Correct |
63 ms |
109948 KB |
Output is correct |
40 |
Correct |
68 ms |
110072 KB |
Output is correct |
41 |
Correct |
62 ms |
110072 KB |
Output is correct |
42 |
Correct |
62 ms |
109944 KB |
Output is correct |
43 |
Correct |
63 ms |
109944 KB |
Output is correct |
44 |
Correct |
63 ms |
110076 KB |
Output is correct |
45 |
Correct |
64 ms |
110072 KB |
Output is correct |
46 |
Correct |
163 ms |
112764 KB |
Output is correct |
47 |
Correct |
192 ms |
112632 KB |
Output is correct |
48 |
Correct |
199 ms |
112640 KB |
Output is correct |
49 |
Correct |
211 ms |
112760 KB |
Output is correct |
50 |
Correct |
239 ms |
112632 KB |
Output is correct |
51 |
Correct |
189 ms |
112632 KB |
Output is correct |
52 |
Correct |
130 ms |
111352 KB |
Output is correct |
53 |
Correct |
99 ms |
110712 KB |
Output is correct |
54 |
Correct |
193 ms |
112632 KB |
Output is correct |
55 |
Correct |
220 ms |
112632 KB |
Output is correct |
56 |
Correct |
210 ms |
112840 KB |
Output is correct |
57 |
Correct |
192 ms |
112632 KB |
Output is correct |
58 |
Correct |
207 ms |
112636 KB |
Output is correct |
59 |
Correct |
226 ms |
112760 KB |
Output is correct |
60 |
Correct |
207 ms |
112632 KB |
Output is correct |
61 |
Correct |
589 ms |
123768 KB |
Output is correct |
62 |
Correct |
600 ms |
123772 KB |
Output is correct |
63 |
Correct |
697 ms |
123640 KB |
Output is correct |
64 |
Runtime error |
596 ms |
250360 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
65 |
Halted |
0 ms |
0 KB |
- |