#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() {
int n,N=1;
cin>>n;
while (N<n)
N*=2;
for (int i=0;i<2*N;i++)
tree[i]=2000000000000000000ll;
for (int i=1;i<=n;i++) {
int x;
scanf("%d",&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;
}
Compilation message
segments.cpp: In function 'int main()':
segments.cpp:26:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
while (N<n)
^~~~~
segments.cpp:28:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
for (int i=0;i<2*N;i++)
^~~
segments.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&x);
~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
252 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
248 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
252 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
248 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
6 ms |
380 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
6 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
252 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
248 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
6 ms |
380 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
6 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
9 ms |
380 KB |
Output is correct |
32 |
Correct |
11 ms |
376 KB |
Output is correct |
33 |
Correct |
11 ms |
504 KB |
Output is correct |
34 |
Correct |
10 ms |
376 KB |
Output is correct |
35 |
Correct |
11 ms |
376 KB |
Output is correct |
36 |
Correct |
11 ms |
376 KB |
Output is correct |
37 |
Correct |
10 ms |
376 KB |
Output is correct |
38 |
Correct |
9 ms |
504 KB |
Output is correct |
39 |
Correct |
11 ms |
376 KB |
Output is correct |
40 |
Correct |
11 ms |
376 KB |
Output is correct |
41 |
Correct |
10 ms |
376 KB |
Output is correct |
42 |
Correct |
10 ms |
376 KB |
Output is correct |
43 |
Correct |
11 ms |
376 KB |
Output is correct |
44 |
Correct |
11 ms |
376 KB |
Output is correct |
45 |
Correct |
10 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
252 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
248 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
6 ms |
380 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
6 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
9 ms |
380 KB |
Output is correct |
32 |
Correct |
11 ms |
376 KB |
Output is correct |
33 |
Correct |
11 ms |
504 KB |
Output is correct |
34 |
Correct |
10 ms |
376 KB |
Output is correct |
35 |
Correct |
11 ms |
376 KB |
Output is correct |
36 |
Correct |
11 ms |
376 KB |
Output is correct |
37 |
Correct |
10 ms |
376 KB |
Output is correct |
38 |
Correct |
9 ms |
504 KB |
Output is correct |
39 |
Correct |
11 ms |
376 KB |
Output is correct |
40 |
Correct |
11 ms |
376 KB |
Output is correct |
41 |
Correct |
10 ms |
376 KB |
Output is correct |
42 |
Correct |
10 ms |
376 KB |
Output is correct |
43 |
Correct |
11 ms |
376 KB |
Output is correct |
44 |
Correct |
11 ms |
376 KB |
Output is correct |
45 |
Correct |
10 ms |
376 KB |
Output is correct |
46 |
Correct |
195 ms |
3580 KB |
Output is correct |
47 |
Correct |
381 ms |
3708 KB |
Output is correct |
48 |
Correct |
362 ms |
3652 KB |
Output is correct |
49 |
Correct |
370 ms |
3576 KB |
Output is correct |
50 |
Correct |
370 ms |
3576 KB |
Output is correct |
51 |
Correct |
368 ms |
3576 KB |
Output is correct |
52 |
Correct |
177 ms |
2040 KB |
Output is correct |
53 |
Correct |
96 ms |
1144 KB |
Output is correct |
54 |
Correct |
377 ms |
3704 KB |
Output is correct |
55 |
Correct |
384 ms |
3576 KB |
Output is correct |
56 |
Correct |
356 ms |
3556 KB |
Output is correct |
57 |
Correct |
348 ms |
3576 KB |
Output is correct |
58 |
Correct |
400 ms |
3576 KB |
Output is correct |
59 |
Correct |
365 ms |
3576 KB |
Output is correct |
60 |
Correct |
381 ms |
3544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
252 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
248 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
6 ms |
380 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
6 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
9 ms |
380 KB |
Output is correct |
32 |
Correct |
11 ms |
376 KB |
Output is correct |
33 |
Correct |
11 ms |
504 KB |
Output is correct |
34 |
Correct |
10 ms |
376 KB |
Output is correct |
35 |
Correct |
11 ms |
376 KB |
Output is correct |
36 |
Correct |
11 ms |
376 KB |
Output is correct |
37 |
Correct |
10 ms |
376 KB |
Output is correct |
38 |
Correct |
9 ms |
504 KB |
Output is correct |
39 |
Correct |
11 ms |
376 KB |
Output is correct |
40 |
Correct |
11 ms |
376 KB |
Output is correct |
41 |
Correct |
10 ms |
376 KB |
Output is correct |
42 |
Correct |
10 ms |
376 KB |
Output is correct |
43 |
Correct |
11 ms |
376 KB |
Output is correct |
44 |
Correct |
11 ms |
376 KB |
Output is correct |
45 |
Correct |
10 ms |
376 KB |
Output is correct |
46 |
Correct |
195 ms |
3580 KB |
Output is correct |
47 |
Correct |
381 ms |
3708 KB |
Output is correct |
48 |
Correct |
362 ms |
3652 KB |
Output is correct |
49 |
Correct |
370 ms |
3576 KB |
Output is correct |
50 |
Correct |
370 ms |
3576 KB |
Output is correct |
51 |
Correct |
368 ms |
3576 KB |
Output is correct |
52 |
Correct |
177 ms |
2040 KB |
Output is correct |
53 |
Correct |
96 ms |
1144 KB |
Output is correct |
54 |
Correct |
377 ms |
3704 KB |
Output is correct |
55 |
Correct |
384 ms |
3576 KB |
Output is correct |
56 |
Correct |
356 ms |
3556 KB |
Output is correct |
57 |
Correct |
348 ms |
3576 KB |
Output is correct |
58 |
Correct |
400 ms |
3576 KB |
Output is correct |
59 |
Correct |
365 ms |
3576 KB |
Output is correct |
60 |
Correct |
381 ms |
3544 KB |
Output is correct |
61 |
Correct |
1204 ms |
14456 KB |
Output is correct |
62 |
Execution timed out |
1580 ms |
14072 KB |
Time limit exceeded |
63 |
Halted |
0 ms |
0 KB |
- |