#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const int N = 5e5+10;
const int K = 20;
const ll INF = 1e18;
ll a[N], p[N], x[N], lg[N], st[K][N], dp[N], n;
ll que(int l, int r) {
int i=lg[l-r+1];
return min(st[i][l], st[i][r+(1<<i)-1]);
}
int main() {
cin>>n;
for (int i=1; i<=n; ++i) cin>>a[i], p[i]=p[i-1]+a[i];
lg[1]=0;
for (int i=2; i<N; ++i) lg[i]=lg[i/2]+1;
for (int i=1; i<=n; ++i) {
for (int j=0; j<K; ++j) st[j][i]=INF;
}
for (int j=1; j<K; ++j) st[j][1]=0;
st[0][1]=2*p[1], dp[1]=1, x[1]=2*p[1];
for (int i=2; i<=n; ++i) {
int l=1, r=i-1, res=0;
while (l <= r) {
int m=(l+r)/2;
if (que(i-1, m) <= p[i]) l=m+1, res=m;
else r=m-1;
} x[i]=p[i]-p[res]+p[i];
dp[i]=dp[res]+1;
st[0][i]=x[i];
for (int j=1; j<K; ++j) {
st[j][i]=min(st[j-1][i], i-(1<<(j-1)) >= 0 ? st[j-1][i-(1<<(j-1))] : 0);
}
}
cout<<dp[n]<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
49500 KB |
Output is correct |
2 |
Correct |
5 ms |
49596 KB |
Output is correct |
3 |
Correct |
5 ms |
49500 KB |
Output is correct |
4 |
Correct |
5 ms |
49500 KB |
Output is correct |
5 |
Correct |
5 ms |
49628 KB |
Output is correct |
6 |
Correct |
5 ms |
49500 KB |
Output is correct |
7 |
Correct |
5 ms |
49496 KB |
Output is correct |
8 |
Correct |
5 ms |
49500 KB |
Output is correct |
9 |
Correct |
5 ms |
49636 KB |
Output is correct |
10 |
Correct |
5 ms |
49500 KB |
Output is correct |
11 |
Correct |
5 ms |
49500 KB |
Output is correct |
12 |
Correct |
5 ms |
49500 KB |
Output is correct |
13 |
Correct |
5 ms |
49500 KB |
Output is correct |
14 |
Correct |
5 ms |
49496 KB |
Output is correct |
15 |
Correct |
5 ms |
49500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
49500 KB |
Output is correct |
2 |
Correct |
5 ms |
49596 KB |
Output is correct |
3 |
Correct |
5 ms |
49500 KB |
Output is correct |
4 |
Correct |
5 ms |
49500 KB |
Output is correct |
5 |
Correct |
5 ms |
49628 KB |
Output is correct |
6 |
Correct |
5 ms |
49500 KB |
Output is correct |
7 |
Correct |
5 ms |
49496 KB |
Output is correct |
8 |
Correct |
5 ms |
49500 KB |
Output is correct |
9 |
Correct |
5 ms |
49636 KB |
Output is correct |
10 |
Correct |
5 ms |
49500 KB |
Output is correct |
11 |
Correct |
5 ms |
49500 KB |
Output is correct |
12 |
Correct |
5 ms |
49500 KB |
Output is correct |
13 |
Correct |
5 ms |
49500 KB |
Output is correct |
14 |
Correct |
5 ms |
49496 KB |
Output is correct |
15 |
Correct |
5 ms |
49500 KB |
Output is correct |
16 |
Correct |
5 ms |
49500 KB |
Output is correct |
17 |
Correct |
5 ms |
49596 KB |
Output is correct |
18 |
Correct |
6 ms |
49624 KB |
Output is correct |
19 |
Correct |
6 ms |
49500 KB |
Output is correct |
20 |
Correct |
5 ms |
49596 KB |
Output is correct |
21 |
Correct |
5 ms |
49500 KB |
Output is correct |
22 |
Correct |
6 ms |
49688 KB |
Output is correct |
23 |
Correct |
6 ms |
49500 KB |
Output is correct |
24 |
Correct |
5 ms |
49596 KB |
Output is correct |
25 |
Correct |
6 ms |
49496 KB |
Output is correct |
26 |
Correct |
5 ms |
49500 KB |
Output is correct |
27 |
Correct |
6 ms |
49500 KB |
Output is correct |
28 |
Correct |
5 ms |
49500 KB |
Output is correct |
29 |
Correct |
5 ms |
49708 KB |
Output is correct |
30 |
Correct |
5 ms |
49704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
49500 KB |
Output is correct |
2 |
Correct |
5 ms |
49596 KB |
Output is correct |
3 |
Correct |
5 ms |
49500 KB |
Output is correct |
4 |
Correct |
5 ms |
49500 KB |
Output is correct |
5 |
Correct |
5 ms |
49628 KB |
Output is correct |
6 |
Correct |
5 ms |
49500 KB |
Output is correct |
7 |
Correct |
5 ms |
49496 KB |
Output is correct |
8 |
Correct |
5 ms |
49500 KB |
Output is correct |
9 |
Correct |
5 ms |
49636 KB |
Output is correct |
10 |
Correct |
5 ms |
49500 KB |
Output is correct |
11 |
Correct |
5 ms |
49500 KB |
Output is correct |
12 |
Correct |
5 ms |
49500 KB |
Output is correct |
13 |
Correct |
5 ms |
49500 KB |
Output is correct |
14 |
Correct |
5 ms |
49496 KB |
Output is correct |
15 |
Correct |
5 ms |
49500 KB |
Output is correct |
16 |
Correct |
5 ms |
49500 KB |
Output is correct |
17 |
Correct |
5 ms |
49596 KB |
Output is correct |
18 |
Correct |
6 ms |
49624 KB |
Output is correct |
19 |
Correct |
6 ms |
49500 KB |
Output is correct |
20 |
Correct |
5 ms |
49596 KB |
Output is correct |
21 |
Correct |
5 ms |
49500 KB |
Output is correct |
22 |
Correct |
6 ms |
49688 KB |
Output is correct |
23 |
Correct |
6 ms |
49500 KB |
Output is correct |
24 |
Correct |
5 ms |
49596 KB |
Output is correct |
25 |
Correct |
6 ms |
49496 KB |
Output is correct |
26 |
Correct |
5 ms |
49500 KB |
Output is correct |
27 |
Correct |
6 ms |
49500 KB |
Output is correct |
28 |
Correct |
5 ms |
49500 KB |
Output is correct |
29 |
Correct |
5 ms |
49708 KB |
Output is correct |
30 |
Correct |
5 ms |
49704 KB |
Output is correct |
31 |
Correct |
6 ms |
49752 KB |
Output is correct |
32 |
Correct |
7 ms |
49608 KB |
Output is correct |
33 |
Correct |
6 ms |
49756 KB |
Output is correct |
34 |
Correct |
6 ms |
49752 KB |
Output is correct |
35 |
Correct |
6 ms |
49756 KB |
Output is correct |
36 |
Correct |
6 ms |
49652 KB |
Output is correct |
37 |
Correct |
6 ms |
49756 KB |
Output is correct |
38 |
Correct |
6 ms |
49500 KB |
Output is correct |
39 |
Correct |
6 ms |
49612 KB |
Output is correct |
40 |
Correct |
6 ms |
49684 KB |
Output is correct |
41 |
Correct |
6 ms |
49768 KB |
Output is correct |
42 |
Correct |
6 ms |
49768 KB |
Output is correct |
43 |
Correct |
6 ms |
49664 KB |
Output is correct |
44 |
Correct |
6 ms |
49764 KB |
Output is correct |
45 |
Correct |
6 ms |
49752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
49500 KB |
Output is correct |
2 |
Correct |
5 ms |
49596 KB |
Output is correct |
3 |
Correct |
5 ms |
49500 KB |
Output is correct |
4 |
Correct |
5 ms |
49500 KB |
Output is correct |
5 |
Correct |
5 ms |
49628 KB |
Output is correct |
6 |
Correct |
5 ms |
49500 KB |
Output is correct |
7 |
Correct |
5 ms |
49496 KB |
Output is correct |
8 |
Correct |
5 ms |
49500 KB |
Output is correct |
9 |
Correct |
5 ms |
49636 KB |
Output is correct |
10 |
Correct |
5 ms |
49500 KB |
Output is correct |
11 |
Correct |
5 ms |
49500 KB |
Output is correct |
12 |
Correct |
5 ms |
49500 KB |
Output is correct |
13 |
Correct |
5 ms |
49500 KB |
Output is correct |
14 |
Correct |
5 ms |
49496 KB |
Output is correct |
15 |
Correct |
5 ms |
49500 KB |
Output is correct |
16 |
Correct |
5 ms |
49500 KB |
Output is correct |
17 |
Correct |
5 ms |
49596 KB |
Output is correct |
18 |
Correct |
6 ms |
49624 KB |
Output is correct |
19 |
Correct |
6 ms |
49500 KB |
Output is correct |
20 |
Correct |
5 ms |
49596 KB |
Output is correct |
21 |
Correct |
5 ms |
49500 KB |
Output is correct |
22 |
Correct |
6 ms |
49688 KB |
Output is correct |
23 |
Correct |
6 ms |
49500 KB |
Output is correct |
24 |
Correct |
5 ms |
49596 KB |
Output is correct |
25 |
Correct |
6 ms |
49496 KB |
Output is correct |
26 |
Correct |
5 ms |
49500 KB |
Output is correct |
27 |
Correct |
6 ms |
49500 KB |
Output is correct |
28 |
Correct |
5 ms |
49500 KB |
Output is correct |
29 |
Correct |
5 ms |
49708 KB |
Output is correct |
30 |
Correct |
5 ms |
49704 KB |
Output is correct |
31 |
Correct |
6 ms |
49752 KB |
Output is correct |
32 |
Correct |
7 ms |
49608 KB |
Output is correct |
33 |
Correct |
6 ms |
49756 KB |
Output is correct |
34 |
Correct |
6 ms |
49752 KB |
Output is correct |
35 |
Correct |
6 ms |
49756 KB |
Output is correct |
36 |
Correct |
6 ms |
49652 KB |
Output is correct |
37 |
Correct |
6 ms |
49756 KB |
Output is correct |
38 |
Correct |
6 ms |
49500 KB |
Output is correct |
39 |
Correct |
6 ms |
49612 KB |
Output is correct |
40 |
Correct |
6 ms |
49684 KB |
Output is correct |
41 |
Correct |
6 ms |
49768 KB |
Output is correct |
42 |
Correct |
6 ms |
49768 KB |
Output is correct |
43 |
Correct |
6 ms |
49664 KB |
Output is correct |
44 |
Correct |
6 ms |
49764 KB |
Output is correct |
45 |
Correct |
6 ms |
49752 KB |
Output is correct |
46 |
Correct |
31 ms |
73040 KB |
Output is correct |
47 |
Correct |
37 ms |
73552 KB |
Output is correct |
48 |
Correct |
39 ms |
73500 KB |
Output is correct |
49 |
Correct |
49 ms |
73572 KB |
Output is correct |
50 |
Correct |
43 ms |
73816 KB |
Output is correct |
51 |
Correct |
43 ms |
73820 KB |
Output is correct |
52 |
Correct |
24 ms |
60752 KB |
Output is correct |
53 |
Correct |
16 ms |
56408 KB |
Output is correct |
54 |
Correct |
27 ms |
73040 KB |
Output is correct |
55 |
Correct |
50 ms |
73636 KB |
Output is correct |
56 |
Correct |
32 ms |
73560 KB |
Output is correct |
57 |
Correct |
34 ms |
73044 KB |
Output is correct |
58 |
Correct |
37 ms |
73296 KB |
Output is correct |
59 |
Correct |
34 ms |
73300 KB |
Output is correct |
60 |
Correct |
35 ms |
73308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
49500 KB |
Output is correct |
2 |
Correct |
5 ms |
49596 KB |
Output is correct |
3 |
Correct |
5 ms |
49500 KB |
Output is correct |
4 |
Correct |
5 ms |
49500 KB |
Output is correct |
5 |
Correct |
5 ms |
49628 KB |
Output is correct |
6 |
Correct |
5 ms |
49500 KB |
Output is correct |
7 |
Correct |
5 ms |
49496 KB |
Output is correct |
8 |
Correct |
5 ms |
49500 KB |
Output is correct |
9 |
Correct |
5 ms |
49636 KB |
Output is correct |
10 |
Correct |
5 ms |
49500 KB |
Output is correct |
11 |
Correct |
5 ms |
49500 KB |
Output is correct |
12 |
Correct |
5 ms |
49500 KB |
Output is correct |
13 |
Correct |
5 ms |
49500 KB |
Output is correct |
14 |
Correct |
5 ms |
49496 KB |
Output is correct |
15 |
Correct |
5 ms |
49500 KB |
Output is correct |
16 |
Correct |
5 ms |
49500 KB |
Output is correct |
17 |
Correct |
5 ms |
49596 KB |
Output is correct |
18 |
Correct |
6 ms |
49624 KB |
Output is correct |
19 |
Correct |
6 ms |
49500 KB |
Output is correct |
20 |
Correct |
5 ms |
49596 KB |
Output is correct |
21 |
Correct |
5 ms |
49500 KB |
Output is correct |
22 |
Correct |
6 ms |
49688 KB |
Output is correct |
23 |
Correct |
6 ms |
49500 KB |
Output is correct |
24 |
Correct |
5 ms |
49596 KB |
Output is correct |
25 |
Correct |
6 ms |
49496 KB |
Output is correct |
26 |
Correct |
5 ms |
49500 KB |
Output is correct |
27 |
Correct |
6 ms |
49500 KB |
Output is correct |
28 |
Correct |
5 ms |
49500 KB |
Output is correct |
29 |
Correct |
5 ms |
49708 KB |
Output is correct |
30 |
Correct |
5 ms |
49704 KB |
Output is correct |
31 |
Correct |
6 ms |
49752 KB |
Output is correct |
32 |
Correct |
7 ms |
49608 KB |
Output is correct |
33 |
Correct |
6 ms |
49756 KB |
Output is correct |
34 |
Correct |
6 ms |
49752 KB |
Output is correct |
35 |
Correct |
6 ms |
49756 KB |
Output is correct |
36 |
Correct |
6 ms |
49652 KB |
Output is correct |
37 |
Correct |
6 ms |
49756 KB |
Output is correct |
38 |
Correct |
6 ms |
49500 KB |
Output is correct |
39 |
Correct |
6 ms |
49612 KB |
Output is correct |
40 |
Correct |
6 ms |
49684 KB |
Output is correct |
41 |
Correct |
6 ms |
49768 KB |
Output is correct |
42 |
Correct |
6 ms |
49768 KB |
Output is correct |
43 |
Correct |
6 ms |
49664 KB |
Output is correct |
44 |
Correct |
6 ms |
49764 KB |
Output is correct |
45 |
Correct |
6 ms |
49752 KB |
Output is correct |
46 |
Correct |
31 ms |
73040 KB |
Output is correct |
47 |
Correct |
37 ms |
73552 KB |
Output is correct |
48 |
Correct |
39 ms |
73500 KB |
Output is correct |
49 |
Correct |
49 ms |
73572 KB |
Output is correct |
50 |
Correct |
43 ms |
73816 KB |
Output is correct |
51 |
Correct |
43 ms |
73820 KB |
Output is correct |
52 |
Correct |
24 ms |
60752 KB |
Output is correct |
53 |
Correct |
16 ms |
56408 KB |
Output is correct |
54 |
Correct |
27 ms |
73040 KB |
Output is correct |
55 |
Correct |
50 ms |
73636 KB |
Output is correct |
56 |
Correct |
32 ms |
73560 KB |
Output is correct |
57 |
Correct |
34 ms |
73044 KB |
Output is correct |
58 |
Correct |
37 ms |
73296 KB |
Output is correct |
59 |
Correct |
34 ms |
73300 KB |
Output is correct |
60 |
Correct |
35 ms |
73308 KB |
Output is correct |
61 |
Correct |
145 ms |
100084 KB |
Output is correct |
62 |
Correct |
144 ms |
100212 KB |
Output is correct |
63 |
Correct |
166 ms |
100800 KB |
Output is correct |
64 |
Correct |
194 ms |
102736 KB |
Output is correct |
65 |
Correct |
199 ms |
102992 KB |
Output is correct |
66 |
Correct |
214 ms |
102960 KB |
Output is correct |
67 |
Correct |
175 ms |
100512 KB |
Output is correct |
68 |
Correct |
86 ms |
93264 KB |
Output is correct |
69 |
Correct |
124 ms |
99180 KB |
Output is correct |
70 |
Correct |
204 ms |
102992 KB |
Output is correct |
71 |
Correct |
137 ms |
100180 KB |
Output is correct |
72 |
Correct |
154 ms |
100472 KB |
Output is correct |
73 |
Correct |
162 ms |
101128 KB |
Output is correct |
74 |
Correct |
165 ms |
101460 KB |
Output is correct |
75 |
Correct |
167 ms |
101460 KB |
Output is correct |