#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)5e5 + 10;
const ll inf = (ll)1e18;
ll A[N];
ll P[N];
ll dp[N];
ll sum[N];
ll val[N * 4 + 512];
int fin(int node, int cl, int cr, ll F){
if(cl == cr){
return cl;
}
int mid = (cl + cr) / 2;
if(val[node * 2 + 1] <= F){
return fin(node * 2 + 1, mid + 1, cr, F);
}
else{
return fin(node * 2, cl, mid, F);
}
}
void update(int node, int cl, int cr, int id, ll v){
if(cl == cr){
val[node] = v;
return;
}
int mid = (cl + cr) / 2;
if(mid >= id)
update(node * 2, cl, mid, id, v);
else
update(node * 2 + 1, mid + 1, cr, id, v);
val[node] = min(val[node * 2], val[node * 2 + 1]);
}
int main(){
fastIO;
//freopen("in.txt","r",stdin);
int n;
cin >> n;
for(int i = 1; i <= N * 4 + 128; i ++ ){
val[i] = inf;
}
for(int i = 1; i <= n; i ++ ){
cin >> A[i];
P[i] = A[i] + P[i - 1];
}
update(1, 0, n, 0, 0);
int idx;
for(int i = 1; i <= n; i ++ ){
idx = fin(1, 0, n, P[i]);
dp[i] = dp[idx] + 1;
sum[i] = P[i] - P[idx];
update(1, 0, n, i, sum[i]+P[i]);
}
cout << dp[n] << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
15948 KB |
Output is correct |
2 |
Correct |
8 ms |
15932 KB |
Output is correct |
3 |
Correct |
7 ms |
15948 KB |
Output is correct |
4 |
Correct |
7 ms |
15876 KB |
Output is correct |
5 |
Correct |
7 ms |
16004 KB |
Output is correct |
6 |
Correct |
8 ms |
15948 KB |
Output is correct |
7 |
Correct |
8 ms |
15948 KB |
Output is correct |
8 |
Correct |
8 ms |
15948 KB |
Output is correct |
9 |
Correct |
8 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15948 KB |
Output is correct |
11 |
Correct |
9 ms |
15948 KB |
Output is correct |
12 |
Correct |
8 ms |
15996 KB |
Output is correct |
13 |
Correct |
9 ms |
15900 KB |
Output is correct |
14 |
Correct |
8 ms |
15912 KB |
Output is correct |
15 |
Correct |
8 ms |
15948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
15948 KB |
Output is correct |
2 |
Correct |
8 ms |
15932 KB |
Output is correct |
3 |
Correct |
7 ms |
15948 KB |
Output is correct |
4 |
Correct |
7 ms |
15876 KB |
Output is correct |
5 |
Correct |
7 ms |
16004 KB |
Output is correct |
6 |
Correct |
8 ms |
15948 KB |
Output is correct |
7 |
Correct |
8 ms |
15948 KB |
Output is correct |
8 |
Correct |
8 ms |
15948 KB |
Output is correct |
9 |
Correct |
8 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15948 KB |
Output is correct |
11 |
Correct |
9 ms |
15948 KB |
Output is correct |
12 |
Correct |
8 ms |
15996 KB |
Output is correct |
13 |
Correct |
9 ms |
15900 KB |
Output is correct |
14 |
Correct |
8 ms |
15912 KB |
Output is correct |
15 |
Correct |
8 ms |
15948 KB |
Output is correct |
16 |
Correct |
8 ms |
15948 KB |
Output is correct |
17 |
Correct |
7 ms |
15948 KB |
Output is correct |
18 |
Correct |
8 ms |
15948 KB |
Output is correct |
19 |
Correct |
9 ms |
15928 KB |
Output is correct |
20 |
Correct |
10 ms |
15948 KB |
Output is correct |
21 |
Correct |
8 ms |
15948 KB |
Output is correct |
22 |
Correct |
8 ms |
15948 KB |
Output is correct |
23 |
Correct |
8 ms |
15932 KB |
Output is correct |
24 |
Correct |
8 ms |
15948 KB |
Output is correct |
25 |
Correct |
9 ms |
15948 KB |
Output is correct |
26 |
Correct |
9 ms |
16076 KB |
Output is correct |
27 |
Correct |
9 ms |
15948 KB |
Output is correct |
28 |
Correct |
8 ms |
15948 KB |
Output is correct |
29 |
Correct |
8 ms |
15948 KB |
Output is correct |
30 |
Correct |
7 ms |
15948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
15948 KB |
Output is correct |
2 |
Correct |
8 ms |
15932 KB |
Output is correct |
3 |
Correct |
7 ms |
15948 KB |
Output is correct |
4 |
Correct |
7 ms |
15876 KB |
Output is correct |
5 |
Correct |
7 ms |
16004 KB |
Output is correct |
6 |
Correct |
8 ms |
15948 KB |
Output is correct |
7 |
Correct |
8 ms |
15948 KB |
Output is correct |
8 |
Correct |
8 ms |
15948 KB |
Output is correct |
9 |
Correct |
8 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15948 KB |
Output is correct |
11 |
Correct |
9 ms |
15948 KB |
Output is correct |
12 |
Correct |
8 ms |
15996 KB |
Output is correct |
13 |
Correct |
9 ms |
15900 KB |
Output is correct |
14 |
Correct |
8 ms |
15912 KB |
Output is correct |
15 |
Correct |
8 ms |
15948 KB |
Output is correct |
16 |
Correct |
8 ms |
15948 KB |
Output is correct |
17 |
Correct |
7 ms |
15948 KB |
Output is correct |
18 |
Correct |
8 ms |
15948 KB |
Output is correct |
19 |
Correct |
9 ms |
15928 KB |
Output is correct |
20 |
Correct |
10 ms |
15948 KB |
Output is correct |
21 |
Correct |
8 ms |
15948 KB |
Output is correct |
22 |
Correct |
8 ms |
15948 KB |
Output is correct |
23 |
Correct |
8 ms |
15932 KB |
Output is correct |
24 |
Correct |
8 ms |
15948 KB |
Output is correct |
25 |
Correct |
9 ms |
15948 KB |
Output is correct |
26 |
Correct |
9 ms |
16076 KB |
Output is correct |
27 |
Correct |
9 ms |
15948 KB |
Output is correct |
28 |
Correct |
8 ms |
15948 KB |
Output is correct |
29 |
Correct |
8 ms |
15948 KB |
Output is correct |
30 |
Correct |
7 ms |
15948 KB |
Output is correct |
31 |
Correct |
8 ms |
16076 KB |
Output is correct |
32 |
Correct |
9 ms |
16032 KB |
Output is correct |
33 |
Correct |
8 ms |
16076 KB |
Output is correct |
34 |
Correct |
9 ms |
16108 KB |
Output is correct |
35 |
Correct |
9 ms |
16076 KB |
Output is correct |
36 |
Correct |
9 ms |
16076 KB |
Output is correct |
37 |
Correct |
8 ms |
16076 KB |
Output is correct |
38 |
Correct |
8 ms |
16076 KB |
Output is correct |
39 |
Correct |
8 ms |
16076 KB |
Output is correct |
40 |
Correct |
9 ms |
16076 KB |
Output is correct |
41 |
Correct |
9 ms |
16076 KB |
Output is correct |
42 |
Correct |
10 ms |
16072 KB |
Output is correct |
43 |
Correct |
9 ms |
15988 KB |
Output is correct |
44 |
Correct |
8 ms |
16076 KB |
Output is correct |
45 |
Correct |
9 ms |
16108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
15948 KB |
Output is correct |
2 |
Correct |
8 ms |
15932 KB |
Output is correct |
3 |
Correct |
7 ms |
15948 KB |
Output is correct |
4 |
Correct |
7 ms |
15876 KB |
Output is correct |
5 |
Correct |
7 ms |
16004 KB |
Output is correct |
6 |
Correct |
8 ms |
15948 KB |
Output is correct |
7 |
Correct |
8 ms |
15948 KB |
Output is correct |
8 |
Correct |
8 ms |
15948 KB |
Output is correct |
9 |
Correct |
8 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15948 KB |
Output is correct |
11 |
Correct |
9 ms |
15948 KB |
Output is correct |
12 |
Correct |
8 ms |
15996 KB |
Output is correct |
13 |
Correct |
9 ms |
15900 KB |
Output is correct |
14 |
Correct |
8 ms |
15912 KB |
Output is correct |
15 |
Correct |
8 ms |
15948 KB |
Output is correct |
16 |
Correct |
8 ms |
15948 KB |
Output is correct |
17 |
Correct |
7 ms |
15948 KB |
Output is correct |
18 |
Correct |
8 ms |
15948 KB |
Output is correct |
19 |
Correct |
9 ms |
15928 KB |
Output is correct |
20 |
Correct |
10 ms |
15948 KB |
Output is correct |
21 |
Correct |
8 ms |
15948 KB |
Output is correct |
22 |
Correct |
8 ms |
15948 KB |
Output is correct |
23 |
Correct |
8 ms |
15932 KB |
Output is correct |
24 |
Correct |
8 ms |
15948 KB |
Output is correct |
25 |
Correct |
9 ms |
15948 KB |
Output is correct |
26 |
Correct |
9 ms |
16076 KB |
Output is correct |
27 |
Correct |
9 ms |
15948 KB |
Output is correct |
28 |
Correct |
8 ms |
15948 KB |
Output is correct |
29 |
Correct |
8 ms |
15948 KB |
Output is correct |
30 |
Correct |
7 ms |
15948 KB |
Output is correct |
31 |
Correct |
8 ms |
16076 KB |
Output is correct |
32 |
Correct |
9 ms |
16032 KB |
Output is correct |
33 |
Correct |
8 ms |
16076 KB |
Output is correct |
34 |
Correct |
9 ms |
16108 KB |
Output is correct |
35 |
Correct |
9 ms |
16076 KB |
Output is correct |
36 |
Correct |
9 ms |
16076 KB |
Output is correct |
37 |
Correct |
8 ms |
16076 KB |
Output is correct |
38 |
Correct |
8 ms |
16076 KB |
Output is correct |
39 |
Correct |
8 ms |
16076 KB |
Output is correct |
40 |
Correct |
9 ms |
16076 KB |
Output is correct |
41 |
Correct |
9 ms |
16076 KB |
Output is correct |
42 |
Correct |
10 ms |
16072 KB |
Output is correct |
43 |
Correct |
9 ms |
15988 KB |
Output is correct |
44 |
Correct |
8 ms |
16076 KB |
Output is correct |
45 |
Correct |
9 ms |
16108 KB |
Output is correct |
46 |
Correct |
34 ms |
19412 KB |
Output is correct |
47 |
Correct |
38 ms |
19480 KB |
Output is correct |
48 |
Correct |
39 ms |
19908 KB |
Output is correct |
49 |
Correct |
42 ms |
19996 KB |
Output is correct |
50 |
Correct |
49 ms |
20000 KB |
Output is correct |
51 |
Correct |
50 ms |
20028 KB |
Output is correct |
52 |
Correct |
31 ms |
18004 KB |
Output is correct |
53 |
Correct |
22 ms |
17228 KB |
Output is correct |
54 |
Correct |
37 ms |
19248 KB |
Output is correct |
55 |
Correct |
44 ms |
20040 KB |
Output is correct |
56 |
Correct |
39 ms |
19500 KB |
Output is correct |
57 |
Correct |
38 ms |
19496 KB |
Output is correct |
58 |
Correct |
46 ms |
19520 KB |
Output is correct |
59 |
Correct |
44 ms |
19604 KB |
Output is correct |
60 |
Correct |
40 ms |
19676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
15948 KB |
Output is correct |
2 |
Correct |
8 ms |
15932 KB |
Output is correct |
3 |
Correct |
7 ms |
15948 KB |
Output is correct |
4 |
Correct |
7 ms |
15876 KB |
Output is correct |
5 |
Correct |
7 ms |
16004 KB |
Output is correct |
6 |
Correct |
8 ms |
15948 KB |
Output is correct |
7 |
Correct |
8 ms |
15948 KB |
Output is correct |
8 |
Correct |
8 ms |
15948 KB |
Output is correct |
9 |
Correct |
8 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15948 KB |
Output is correct |
11 |
Correct |
9 ms |
15948 KB |
Output is correct |
12 |
Correct |
8 ms |
15996 KB |
Output is correct |
13 |
Correct |
9 ms |
15900 KB |
Output is correct |
14 |
Correct |
8 ms |
15912 KB |
Output is correct |
15 |
Correct |
8 ms |
15948 KB |
Output is correct |
16 |
Correct |
8 ms |
15948 KB |
Output is correct |
17 |
Correct |
7 ms |
15948 KB |
Output is correct |
18 |
Correct |
8 ms |
15948 KB |
Output is correct |
19 |
Correct |
9 ms |
15928 KB |
Output is correct |
20 |
Correct |
10 ms |
15948 KB |
Output is correct |
21 |
Correct |
8 ms |
15948 KB |
Output is correct |
22 |
Correct |
8 ms |
15948 KB |
Output is correct |
23 |
Correct |
8 ms |
15932 KB |
Output is correct |
24 |
Correct |
8 ms |
15948 KB |
Output is correct |
25 |
Correct |
9 ms |
15948 KB |
Output is correct |
26 |
Correct |
9 ms |
16076 KB |
Output is correct |
27 |
Correct |
9 ms |
15948 KB |
Output is correct |
28 |
Correct |
8 ms |
15948 KB |
Output is correct |
29 |
Correct |
8 ms |
15948 KB |
Output is correct |
30 |
Correct |
7 ms |
15948 KB |
Output is correct |
31 |
Correct |
8 ms |
16076 KB |
Output is correct |
32 |
Correct |
9 ms |
16032 KB |
Output is correct |
33 |
Correct |
8 ms |
16076 KB |
Output is correct |
34 |
Correct |
9 ms |
16108 KB |
Output is correct |
35 |
Correct |
9 ms |
16076 KB |
Output is correct |
36 |
Correct |
9 ms |
16076 KB |
Output is correct |
37 |
Correct |
8 ms |
16076 KB |
Output is correct |
38 |
Correct |
8 ms |
16076 KB |
Output is correct |
39 |
Correct |
8 ms |
16076 KB |
Output is correct |
40 |
Correct |
9 ms |
16076 KB |
Output is correct |
41 |
Correct |
9 ms |
16076 KB |
Output is correct |
42 |
Correct |
10 ms |
16072 KB |
Output is correct |
43 |
Correct |
9 ms |
15988 KB |
Output is correct |
44 |
Correct |
8 ms |
16076 KB |
Output is correct |
45 |
Correct |
9 ms |
16108 KB |
Output is correct |
46 |
Correct |
34 ms |
19412 KB |
Output is correct |
47 |
Correct |
38 ms |
19480 KB |
Output is correct |
48 |
Correct |
39 ms |
19908 KB |
Output is correct |
49 |
Correct |
42 ms |
19996 KB |
Output is correct |
50 |
Correct |
49 ms |
20000 KB |
Output is correct |
51 |
Correct |
50 ms |
20028 KB |
Output is correct |
52 |
Correct |
31 ms |
18004 KB |
Output is correct |
53 |
Correct |
22 ms |
17228 KB |
Output is correct |
54 |
Correct |
37 ms |
19248 KB |
Output is correct |
55 |
Correct |
44 ms |
20040 KB |
Output is correct |
56 |
Correct |
39 ms |
19500 KB |
Output is correct |
57 |
Correct |
38 ms |
19496 KB |
Output is correct |
58 |
Correct |
46 ms |
19520 KB |
Output is correct |
59 |
Correct |
44 ms |
19604 KB |
Output is correct |
60 |
Correct |
40 ms |
19676 KB |
Output is correct |
61 |
Correct |
155 ms |
33532 KB |
Output is correct |
62 |
Correct |
168 ms |
33528 KB |
Output is correct |
63 |
Correct |
169 ms |
33916 KB |
Output is correct |
64 |
Correct |
190 ms |
36164 KB |
Output is correct |
65 |
Correct |
221 ms |
36444 KB |
Output is correct |
66 |
Correct |
207 ms |
36404 KB |
Output is correct |
67 |
Correct |
190 ms |
32272 KB |
Output is correct |
68 |
Correct |
79 ms |
24132 KB |
Output is correct |
69 |
Correct |
166 ms |
32608 KB |
Output is correct |
70 |
Correct |
208 ms |
36408 KB |
Output is correct |
71 |
Correct |
173 ms |
33476 KB |
Output is correct |
72 |
Correct |
169 ms |
33856 KB |
Output is correct |
73 |
Correct |
176 ms |
34484 KB |
Output is correct |
74 |
Correct |
181 ms |
34884 KB |
Output is correct |
75 |
Correct |
180 ms |
34884 KB |
Output is correct |