#include <bits/stdc++.h>
using namespace std;
long long sum[500001],tree[1050000];
int dp[500001];
long long minn(long long a,long long b) {
if (a>b)
return b;
return a;
}
void update(int pos,long long val) {
while (pos) {
tree[pos]=minn(tree[pos],val);
pos/=2;
}
}
long long solve(int p,int l,int r,int x,int y) {
if (x>r || l>y)
return 2000000000000000000ll;
if (l>=x && r<=y)
return tree[p];
return minn(solve(2*p,l,(l+r)/2,x,y),solve(2*p+1,(l+r)/2+1,r,x,y));
}
int main() {
for (int i=0;i<1050000;i++)
tree[i]=2000000000000000000ll;
int n,N=1;
cin>>n;
while (N<n)
N*=2;
for (int i=1;i<=n;i++) {
int x;
cin>>x;
sum[i]=sum[i-1]+x;
int pos=i;
for (int j=18;j>=0;j--)
if (pos-(1<<j)>0 && solve(1,N,2*N-1,pos-(1<<j)+N-1,pos-1+N-1)>sum[i])
pos-=(1<<j);
dp[i]=dp[pos-1]+1;
update(i+N-1,2*sum[i]-sum[pos-1]);
}
cout<<dp[n]<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
8568 KB |
Output is correct |
2 |
Correct |
10 ms |
8568 KB |
Output is correct |
3 |
Correct |
10 ms |
8624 KB |
Output is correct |
4 |
Correct |
9 ms |
8568 KB |
Output is correct |
5 |
Correct |
10 ms |
8568 KB |
Output is correct |
6 |
Correct |
9 ms |
8568 KB |
Output is correct |
7 |
Correct |
9 ms |
8568 KB |
Output is correct |
8 |
Correct |
11 ms |
8568 KB |
Output is correct |
9 |
Correct |
9 ms |
8568 KB |
Output is correct |
10 |
Correct |
9 ms |
8568 KB |
Output is correct |
11 |
Correct |
8 ms |
8568 KB |
Output is correct |
12 |
Correct |
10 ms |
8568 KB |
Output is correct |
13 |
Correct |
9 ms |
8568 KB |
Output is correct |
14 |
Correct |
9 ms |
8568 KB |
Output is correct |
15 |
Correct |
9 ms |
8568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
8568 KB |
Output is correct |
2 |
Correct |
10 ms |
8568 KB |
Output is correct |
3 |
Correct |
10 ms |
8624 KB |
Output is correct |
4 |
Correct |
9 ms |
8568 KB |
Output is correct |
5 |
Correct |
10 ms |
8568 KB |
Output is correct |
6 |
Correct |
9 ms |
8568 KB |
Output is correct |
7 |
Correct |
9 ms |
8568 KB |
Output is correct |
8 |
Correct |
11 ms |
8568 KB |
Output is correct |
9 |
Correct |
9 ms |
8568 KB |
Output is correct |
10 |
Correct |
9 ms |
8568 KB |
Output is correct |
11 |
Correct |
8 ms |
8568 KB |
Output is correct |
12 |
Correct |
10 ms |
8568 KB |
Output is correct |
13 |
Correct |
9 ms |
8568 KB |
Output is correct |
14 |
Correct |
9 ms |
8568 KB |
Output is correct |
15 |
Correct |
9 ms |
8568 KB |
Output is correct |
16 |
Correct |
9 ms |
8568 KB |
Output is correct |
17 |
Correct |
10 ms |
8568 KB |
Output is correct |
18 |
Correct |
10 ms |
8568 KB |
Output is correct |
19 |
Correct |
10 ms |
8572 KB |
Output is correct |
20 |
Correct |
10 ms |
8568 KB |
Output is correct |
21 |
Correct |
7 ms |
8568 KB |
Output is correct |
22 |
Correct |
10 ms |
8568 KB |
Output is correct |
23 |
Correct |
9 ms |
8568 KB |
Output is correct |
24 |
Correct |
10 ms |
8568 KB |
Output is correct |
25 |
Correct |
9 ms |
8568 KB |
Output is correct |
26 |
Correct |
9 ms |
8568 KB |
Output is correct |
27 |
Correct |
10 ms |
8568 KB |
Output is correct |
28 |
Correct |
10 ms |
8568 KB |
Output is correct |
29 |
Correct |
9 ms |
8568 KB |
Output is correct |
30 |
Correct |
10 ms |
8568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
8568 KB |
Output is correct |
2 |
Correct |
10 ms |
8568 KB |
Output is correct |
3 |
Correct |
10 ms |
8624 KB |
Output is correct |
4 |
Correct |
9 ms |
8568 KB |
Output is correct |
5 |
Correct |
10 ms |
8568 KB |
Output is correct |
6 |
Correct |
9 ms |
8568 KB |
Output is correct |
7 |
Correct |
9 ms |
8568 KB |
Output is correct |
8 |
Correct |
11 ms |
8568 KB |
Output is correct |
9 |
Correct |
9 ms |
8568 KB |
Output is correct |
10 |
Correct |
9 ms |
8568 KB |
Output is correct |
11 |
Correct |
8 ms |
8568 KB |
Output is correct |
12 |
Correct |
10 ms |
8568 KB |
Output is correct |
13 |
Correct |
9 ms |
8568 KB |
Output is correct |
14 |
Correct |
9 ms |
8568 KB |
Output is correct |
15 |
Correct |
9 ms |
8568 KB |
Output is correct |
16 |
Correct |
9 ms |
8568 KB |
Output is correct |
17 |
Correct |
10 ms |
8568 KB |
Output is correct |
18 |
Correct |
10 ms |
8568 KB |
Output is correct |
19 |
Correct |
10 ms |
8572 KB |
Output is correct |
20 |
Correct |
10 ms |
8568 KB |
Output is correct |
21 |
Correct |
7 ms |
8568 KB |
Output is correct |
22 |
Correct |
10 ms |
8568 KB |
Output is correct |
23 |
Correct |
9 ms |
8568 KB |
Output is correct |
24 |
Correct |
10 ms |
8568 KB |
Output is correct |
25 |
Correct |
9 ms |
8568 KB |
Output is correct |
26 |
Correct |
9 ms |
8568 KB |
Output is correct |
27 |
Correct |
10 ms |
8568 KB |
Output is correct |
28 |
Correct |
10 ms |
8568 KB |
Output is correct |
29 |
Correct |
9 ms |
8568 KB |
Output is correct |
30 |
Correct |
10 ms |
8568 KB |
Output is correct |
31 |
Correct |
14 ms |
8568 KB |
Output is correct |
32 |
Correct |
15 ms |
8568 KB |
Output is correct |
33 |
Correct |
16 ms |
8568 KB |
Output is correct |
34 |
Correct |
16 ms |
8572 KB |
Output is correct |
35 |
Correct |
17 ms |
8568 KB |
Output is correct |
36 |
Correct |
17 ms |
8568 KB |
Output is correct |
37 |
Correct |
15 ms |
8568 KB |
Output is correct |
38 |
Correct |
14 ms |
8568 KB |
Output is correct |
39 |
Correct |
15 ms |
8568 KB |
Output is correct |
40 |
Correct |
16 ms |
8568 KB |
Output is correct |
41 |
Correct |
15 ms |
8568 KB |
Output is correct |
42 |
Correct |
15 ms |
8568 KB |
Output is correct |
43 |
Correct |
16 ms |
8568 KB |
Output is correct |
44 |
Correct |
15 ms |
8568 KB |
Output is correct |
45 |
Correct |
16 ms |
8568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
8568 KB |
Output is correct |
2 |
Correct |
10 ms |
8568 KB |
Output is correct |
3 |
Correct |
10 ms |
8624 KB |
Output is correct |
4 |
Correct |
9 ms |
8568 KB |
Output is correct |
5 |
Correct |
10 ms |
8568 KB |
Output is correct |
6 |
Correct |
9 ms |
8568 KB |
Output is correct |
7 |
Correct |
9 ms |
8568 KB |
Output is correct |
8 |
Correct |
11 ms |
8568 KB |
Output is correct |
9 |
Correct |
9 ms |
8568 KB |
Output is correct |
10 |
Correct |
9 ms |
8568 KB |
Output is correct |
11 |
Correct |
8 ms |
8568 KB |
Output is correct |
12 |
Correct |
10 ms |
8568 KB |
Output is correct |
13 |
Correct |
9 ms |
8568 KB |
Output is correct |
14 |
Correct |
9 ms |
8568 KB |
Output is correct |
15 |
Correct |
9 ms |
8568 KB |
Output is correct |
16 |
Correct |
9 ms |
8568 KB |
Output is correct |
17 |
Correct |
10 ms |
8568 KB |
Output is correct |
18 |
Correct |
10 ms |
8568 KB |
Output is correct |
19 |
Correct |
10 ms |
8572 KB |
Output is correct |
20 |
Correct |
10 ms |
8568 KB |
Output is correct |
21 |
Correct |
7 ms |
8568 KB |
Output is correct |
22 |
Correct |
10 ms |
8568 KB |
Output is correct |
23 |
Correct |
9 ms |
8568 KB |
Output is correct |
24 |
Correct |
10 ms |
8568 KB |
Output is correct |
25 |
Correct |
9 ms |
8568 KB |
Output is correct |
26 |
Correct |
9 ms |
8568 KB |
Output is correct |
27 |
Correct |
10 ms |
8568 KB |
Output is correct |
28 |
Correct |
10 ms |
8568 KB |
Output is correct |
29 |
Correct |
9 ms |
8568 KB |
Output is correct |
30 |
Correct |
10 ms |
8568 KB |
Output is correct |
31 |
Correct |
14 ms |
8568 KB |
Output is correct |
32 |
Correct |
15 ms |
8568 KB |
Output is correct |
33 |
Correct |
16 ms |
8568 KB |
Output is correct |
34 |
Correct |
16 ms |
8572 KB |
Output is correct |
35 |
Correct |
17 ms |
8568 KB |
Output is correct |
36 |
Correct |
17 ms |
8568 KB |
Output is correct |
37 |
Correct |
15 ms |
8568 KB |
Output is correct |
38 |
Correct |
14 ms |
8568 KB |
Output is correct |
39 |
Correct |
15 ms |
8568 KB |
Output is correct |
40 |
Correct |
16 ms |
8568 KB |
Output is correct |
41 |
Correct |
15 ms |
8568 KB |
Output is correct |
42 |
Correct |
15 ms |
8568 KB |
Output is correct |
43 |
Correct |
16 ms |
8568 KB |
Output is correct |
44 |
Correct |
15 ms |
8568 KB |
Output is correct |
45 |
Correct |
16 ms |
8568 KB |
Output is correct |
46 |
Correct |
217 ms |
9800 KB |
Output is correct |
47 |
Correct |
380 ms |
9732 KB |
Output is correct |
48 |
Correct |
413 ms |
9848 KB |
Output is correct |
49 |
Correct |
396 ms |
9720 KB |
Output is correct |
50 |
Correct |
401 ms |
9760 KB |
Output is correct |
51 |
Correct |
410 ms |
9976 KB |
Output is correct |
52 |
Correct |
202 ms |
9172 KB |
Output is correct |
53 |
Correct |
114 ms |
8824 KB |
Output is correct |
54 |
Correct |
385 ms |
9848 KB |
Output is correct |
55 |
Correct |
419 ms |
9840 KB |
Output is correct |
56 |
Correct |
384 ms |
9892 KB |
Output is correct |
57 |
Correct |
378 ms |
9720 KB |
Output is correct |
58 |
Correct |
386 ms |
9848 KB |
Output is correct |
59 |
Correct |
397 ms |
9724 KB |
Output is correct |
60 |
Correct |
400 ms |
9744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
8568 KB |
Output is correct |
2 |
Correct |
10 ms |
8568 KB |
Output is correct |
3 |
Correct |
10 ms |
8624 KB |
Output is correct |
4 |
Correct |
9 ms |
8568 KB |
Output is correct |
5 |
Correct |
10 ms |
8568 KB |
Output is correct |
6 |
Correct |
9 ms |
8568 KB |
Output is correct |
7 |
Correct |
9 ms |
8568 KB |
Output is correct |
8 |
Correct |
11 ms |
8568 KB |
Output is correct |
9 |
Correct |
9 ms |
8568 KB |
Output is correct |
10 |
Correct |
9 ms |
8568 KB |
Output is correct |
11 |
Correct |
8 ms |
8568 KB |
Output is correct |
12 |
Correct |
10 ms |
8568 KB |
Output is correct |
13 |
Correct |
9 ms |
8568 KB |
Output is correct |
14 |
Correct |
9 ms |
8568 KB |
Output is correct |
15 |
Correct |
9 ms |
8568 KB |
Output is correct |
16 |
Correct |
9 ms |
8568 KB |
Output is correct |
17 |
Correct |
10 ms |
8568 KB |
Output is correct |
18 |
Correct |
10 ms |
8568 KB |
Output is correct |
19 |
Correct |
10 ms |
8572 KB |
Output is correct |
20 |
Correct |
10 ms |
8568 KB |
Output is correct |
21 |
Correct |
7 ms |
8568 KB |
Output is correct |
22 |
Correct |
10 ms |
8568 KB |
Output is correct |
23 |
Correct |
9 ms |
8568 KB |
Output is correct |
24 |
Correct |
10 ms |
8568 KB |
Output is correct |
25 |
Correct |
9 ms |
8568 KB |
Output is correct |
26 |
Correct |
9 ms |
8568 KB |
Output is correct |
27 |
Correct |
10 ms |
8568 KB |
Output is correct |
28 |
Correct |
10 ms |
8568 KB |
Output is correct |
29 |
Correct |
9 ms |
8568 KB |
Output is correct |
30 |
Correct |
10 ms |
8568 KB |
Output is correct |
31 |
Correct |
14 ms |
8568 KB |
Output is correct |
32 |
Correct |
15 ms |
8568 KB |
Output is correct |
33 |
Correct |
16 ms |
8568 KB |
Output is correct |
34 |
Correct |
16 ms |
8572 KB |
Output is correct |
35 |
Correct |
17 ms |
8568 KB |
Output is correct |
36 |
Correct |
17 ms |
8568 KB |
Output is correct |
37 |
Correct |
15 ms |
8568 KB |
Output is correct |
38 |
Correct |
14 ms |
8568 KB |
Output is correct |
39 |
Correct |
15 ms |
8568 KB |
Output is correct |
40 |
Correct |
16 ms |
8568 KB |
Output is correct |
41 |
Correct |
15 ms |
8568 KB |
Output is correct |
42 |
Correct |
15 ms |
8568 KB |
Output is correct |
43 |
Correct |
16 ms |
8568 KB |
Output is correct |
44 |
Correct |
15 ms |
8568 KB |
Output is correct |
45 |
Correct |
16 ms |
8568 KB |
Output is correct |
46 |
Correct |
217 ms |
9800 KB |
Output is correct |
47 |
Correct |
380 ms |
9732 KB |
Output is correct |
48 |
Correct |
413 ms |
9848 KB |
Output is correct |
49 |
Correct |
396 ms |
9720 KB |
Output is correct |
50 |
Correct |
401 ms |
9760 KB |
Output is correct |
51 |
Correct |
410 ms |
9976 KB |
Output is correct |
52 |
Correct |
202 ms |
9172 KB |
Output is correct |
53 |
Correct |
114 ms |
8824 KB |
Output is correct |
54 |
Correct |
385 ms |
9848 KB |
Output is correct |
55 |
Correct |
419 ms |
9840 KB |
Output is correct |
56 |
Correct |
384 ms |
9892 KB |
Output is correct |
57 |
Correct |
378 ms |
9720 KB |
Output is correct |
58 |
Correct |
386 ms |
9848 KB |
Output is correct |
59 |
Correct |
397 ms |
9724 KB |
Output is correct |
60 |
Correct |
400 ms |
9744 KB |
Output is correct |
61 |
Correct |
1311 ms |
14456 KB |
Output is correct |
62 |
Execution timed out |
1587 ms |
13864 KB |
Time limit exceeded |
63 |
Halted |
0 ms |
0 KB |
- |