#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll n,a[500005],s[500005],ans[500005],ind;
vector<pair<ll,ll> >v[500005];
int main(){
ios::sync_with_stdio(false);
cin >> n;
for(int i=1; i<=n; i++){
cin >> a[i];
s[i] = s[i - 1] + a[i];
}
pair<ll,ll> p = make_pair(0 , 0);
for(int i=1; i<=n; i++){
for(int j=0; j<v[i].size(); j++)
if(v[i][j].f > p.f)
p = v[i][j];
else if(v[i][j].f == p.f)
p = max(p , v[i][j]);
ind = p.s;
ans[i] = ans[ind] + 1;
pair<ll,ll> ne = make_pair(ans[i] , i);
ll l = i + 1,r = n,mid,ik = -1;
while(r >= l){
mid = (l + r) / 2;
if(s[mid] - s[i] >= s[i] - s[ind]){
r = mid - 1;
ik = mid;
}
else {
l = mid + 1;
}
}
if(ik != -1){
v[ik].pb(ne);
}
}
cout << ans[n] << endl;
return 0;
}
Compilation message
segments.cpp: In function 'int main()':
segments.cpp:19:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j<v[i].size(); j++)
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12024 KB |
Output is correct |
2 |
Correct |
13 ms |
12152 KB |
Output is correct |
3 |
Correct |
13 ms |
12152 KB |
Output is correct |
4 |
Correct |
13 ms |
12024 KB |
Output is correct |
5 |
Correct |
13 ms |
12152 KB |
Output is correct |
6 |
Correct |
13 ms |
12152 KB |
Output is correct |
7 |
Correct |
13 ms |
12152 KB |
Output is correct |
8 |
Correct |
13 ms |
12152 KB |
Output is correct |
9 |
Correct |
13 ms |
12280 KB |
Output is correct |
10 |
Correct |
16 ms |
12152 KB |
Output is correct |
11 |
Correct |
13 ms |
12152 KB |
Output is correct |
12 |
Correct |
16 ms |
12152 KB |
Output is correct |
13 |
Correct |
13 ms |
12024 KB |
Output is correct |
14 |
Correct |
13 ms |
12024 KB |
Output is correct |
15 |
Correct |
13 ms |
12024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12024 KB |
Output is correct |
2 |
Correct |
13 ms |
12152 KB |
Output is correct |
3 |
Correct |
13 ms |
12152 KB |
Output is correct |
4 |
Correct |
13 ms |
12024 KB |
Output is correct |
5 |
Correct |
13 ms |
12152 KB |
Output is correct |
6 |
Correct |
13 ms |
12152 KB |
Output is correct |
7 |
Correct |
13 ms |
12152 KB |
Output is correct |
8 |
Correct |
13 ms |
12152 KB |
Output is correct |
9 |
Correct |
13 ms |
12280 KB |
Output is correct |
10 |
Correct |
16 ms |
12152 KB |
Output is correct |
11 |
Correct |
13 ms |
12152 KB |
Output is correct |
12 |
Correct |
16 ms |
12152 KB |
Output is correct |
13 |
Correct |
13 ms |
12024 KB |
Output is correct |
14 |
Correct |
13 ms |
12024 KB |
Output is correct |
15 |
Correct |
13 ms |
12024 KB |
Output is correct |
16 |
Correct |
13 ms |
12152 KB |
Output is correct |
17 |
Correct |
13 ms |
12152 KB |
Output is correct |
18 |
Correct |
13 ms |
12124 KB |
Output is correct |
19 |
Correct |
13 ms |
12152 KB |
Output is correct |
20 |
Correct |
13 ms |
12152 KB |
Output is correct |
21 |
Correct |
15 ms |
12024 KB |
Output is correct |
22 |
Correct |
13 ms |
12124 KB |
Output is correct |
23 |
Correct |
13 ms |
12152 KB |
Output is correct |
24 |
Correct |
13 ms |
12152 KB |
Output is correct |
25 |
Correct |
13 ms |
12152 KB |
Output is correct |
26 |
Correct |
13 ms |
12088 KB |
Output is correct |
27 |
Correct |
13 ms |
12152 KB |
Output is correct |
28 |
Correct |
13 ms |
12152 KB |
Output is correct |
29 |
Correct |
13 ms |
12152 KB |
Output is correct |
30 |
Correct |
13 ms |
12152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12024 KB |
Output is correct |
2 |
Correct |
13 ms |
12152 KB |
Output is correct |
3 |
Correct |
13 ms |
12152 KB |
Output is correct |
4 |
Correct |
13 ms |
12024 KB |
Output is correct |
5 |
Correct |
13 ms |
12152 KB |
Output is correct |
6 |
Correct |
13 ms |
12152 KB |
Output is correct |
7 |
Correct |
13 ms |
12152 KB |
Output is correct |
8 |
Correct |
13 ms |
12152 KB |
Output is correct |
9 |
Correct |
13 ms |
12280 KB |
Output is correct |
10 |
Correct |
16 ms |
12152 KB |
Output is correct |
11 |
Correct |
13 ms |
12152 KB |
Output is correct |
12 |
Correct |
16 ms |
12152 KB |
Output is correct |
13 |
Correct |
13 ms |
12024 KB |
Output is correct |
14 |
Correct |
13 ms |
12024 KB |
Output is correct |
15 |
Correct |
13 ms |
12024 KB |
Output is correct |
16 |
Correct |
13 ms |
12152 KB |
Output is correct |
17 |
Correct |
13 ms |
12152 KB |
Output is correct |
18 |
Correct |
13 ms |
12124 KB |
Output is correct |
19 |
Correct |
13 ms |
12152 KB |
Output is correct |
20 |
Correct |
13 ms |
12152 KB |
Output is correct |
21 |
Correct |
15 ms |
12024 KB |
Output is correct |
22 |
Correct |
13 ms |
12124 KB |
Output is correct |
23 |
Correct |
13 ms |
12152 KB |
Output is correct |
24 |
Correct |
13 ms |
12152 KB |
Output is correct |
25 |
Correct |
13 ms |
12152 KB |
Output is correct |
26 |
Correct |
13 ms |
12088 KB |
Output is correct |
27 |
Correct |
13 ms |
12152 KB |
Output is correct |
28 |
Correct |
13 ms |
12152 KB |
Output is correct |
29 |
Correct |
13 ms |
12152 KB |
Output is correct |
30 |
Correct |
13 ms |
12152 KB |
Output is correct |
31 |
Correct |
14 ms |
12152 KB |
Output is correct |
32 |
Correct |
14 ms |
12280 KB |
Output is correct |
33 |
Correct |
14 ms |
12280 KB |
Output is correct |
34 |
Correct |
14 ms |
12284 KB |
Output is correct |
35 |
Correct |
14 ms |
12280 KB |
Output is correct |
36 |
Correct |
18 ms |
12280 KB |
Output is correct |
37 |
Correct |
15 ms |
12280 KB |
Output is correct |
38 |
Correct |
16 ms |
12232 KB |
Output is correct |
39 |
Correct |
14 ms |
12280 KB |
Output is correct |
40 |
Correct |
14 ms |
12252 KB |
Output is correct |
41 |
Correct |
14 ms |
12280 KB |
Output is correct |
42 |
Correct |
14 ms |
12280 KB |
Output is correct |
43 |
Correct |
14 ms |
12280 KB |
Output is correct |
44 |
Correct |
14 ms |
12280 KB |
Output is correct |
45 |
Correct |
14 ms |
12280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12024 KB |
Output is correct |
2 |
Correct |
13 ms |
12152 KB |
Output is correct |
3 |
Correct |
13 ms |
12152 KB |
Output is correct |
4 |
Correct |
13 ms |
12024 KB |
Output is correct |
5 |
Correct |
13 ms |
12152 KB |
Output is correct |
6 |
Correct |
13 ms |
12152 KB |
Output is correct |
7 |
Correct |
13 ms |
12152 KB |
Output is correct |
8 |
Correct |
13 ms |
12152 KB |
Output is correct |
9 |
Correct |
13 ms |
12280 KB |
Output is correct |
10 |
Correct |
16 ms |
12152 KB |
Output is correct |
11 |
Correct |
13 ms |
12152 KB |
Output is correct |
12 |
Correct |
16 ms |
12152 KB |
Output is correct |
13 |
Correct |
13 ms |
12024 KB |
Output is correct |
14 |
Correct |
13 ms |
12024 KB |
Output is correct |
15 |
Correct |
13 ms |
12024 KB |
Output is correct |
16 |
Correct |
13 ms |
12152 KB |
Output is correct |
17 |
Correct |
13 ms |
12152 KB |
Output is correct |
18 |
Correct |
13 ms |
12124 KB |
Output is correct |
19 |
Correct |
13 ms |
12152 KB |
Output is correct |
20 |
Correct |
13 ms |
12152 KB |
Output is correct |
21 |
Correct |
15 ms |
12024 KB |
Output is correct |
22 |
Correct |
13 ms |
12124 KB |
Output is correct |
23 |
Correct |
13 ms |
12152 KB |
Output is correct |
24 |
Correct |
13 ms |
12152 KB |
Output is correct |
25 |
Correct |
13 ms |
12152 KB |
Output is correct |
26 |
Correct |
13 ms |
12088 KB |
Output is correct |
27 |
Correct |
13 ms |
12152 KB |
Output is correct |
28 |
Correct |
13 ms |
12152 KB |
Output is correct |
29 |
Correct |
13 ms |
12152 KB |
Output is correct |
30 |
Correct |
13 ms |
12152 KB |
Output is correct |
31 |
Correct |
14 ms |
12152 KB |
Output is correct |
32 |
Correct |
14 ms |
12280 KB |
Output is correct |
33 |
Correct |
14 ms |
12280 KB |
Output is correct |
34 |
Correct |
14 ms |
12284 KB |
Output is correct |
35 |
Correct |
14 ms |
12280 KB |
Output is correct |
36 |
Correct |
18 ms |
12280 KB |
Output is correct |
37 |
Correct |
15 ms |
12280 KB |
Output is correct |
38 |
Correct |
16 ms |
12232 KB |
Output is correct |
39 |
Correct |
14 ms |
12280 KB |
Output is correct |
40 |
Correct |
14 ms |
12252 KB |
Output is correct |
41 |
Correct |
14 ms |
12280 KB |
Output is correct |
42 |
Correct |
14 ms |
12280 KB |
Output is correct |
43 |
Correct |
14 ms |
12280 KB |
Output is correct |
44 |
Correct |
14 ms |
12280 KB |
Output is correct |
45 |
Correct |
14 ms |
12280 KB |
Output is correct |
46 |
Correct |
29 ms |
14840 KB |
Output is correct |
47 |
Correct |
39 ms |
17272 KB |
Output is correct |
48 |
Correct |
43 ms |
17784 KB |
Output is correct |
49 |
Correct |
40 ms |
18168 KB |
Output is correct |
50 |
Correct |
40 ms |
18552 KB |
Output is correct |
51 |
Correct |
47 ms |
17976 KB |
Output is correct |
52 |
Correct |
29 ms |
15096 KB |
Output is correct |
53 |
Correct |
21 ms |
13944 KB |
Output is correct |
54 |
Correct |
39 ms |
17272 KB |
Output is correct |
55 |
Correct |
47 ms |
18348 KB |
Output is correct |
56 |
Correct |
35 ms |
18040 KB |
Output is correct |
57 |
Correct |
34 ms |
17268 KB |
Output is correct |
58 |
Correct |
41 ms |
17644 KB |
Output is correct |
59 |
Correct |
36 ms |
18168 KB |
Output is correct |
60 |
Correct |
37 ms |
18168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12024 KB |
Output is correct |
2 |
Correct |
13 ms |
12152 KB |
Output is correct |
3 |
Correct |
13 ms |
12152 KB |
Output is correct |
4 |
Correct |
13 ms |
12024 KB |
Output is correct |
5 |
Correct |
13 ms |
12152 KB |
Output is correct |
6 |
Correct |
13 ms |
12152 KB |
Output is correct |
7 |
Correct |
13 ms |
12152 KB |
Output is correct |
8 |
Correct |
13 ms |
12152 KB |
Output is correct |
9 |
Correct |
13 ms |
12280 KB |
Output is correct |
10 |
Correct |
16 ms |
12152 KB |
Output is correct |
11 |
Correct |
13 ms |
12152 KB |
Output is correct |
12 |
Correct |
16 ms |
12152 KB |
Output is correct |
13 |
Correct |
13 ms |
12024 KB |
Output is correct |
14 |
Correct |
13 ms |
12024 KB |
Output is correct |
15 |
Correct |
13 ms |
12024 KB |
Output is correct |
16 |
Correct |
13 ms |
12152 KB |
Output is correct |
17 |
Correct |
13 ms |
12152 KB |
Output is correct |
18 |
Correct |
13 ms |
12124 KB |
Output is correct |
19 |
Correct |
13 ms |
12152 KB |
Output is correct |
20 |
Correct |
13 ms |
12152 KB |
Output is correct |
21 |
Correct |
15 ms |
12024 KB |
Output is correct |
22 |
Correct |
13 ms |
12124 KB |
Output is correct |
23 |
Correct |
13 ms |
12152 KB |
Output is correct |
24 |
Correct |
13 ms |
12152 KB |
Output is correct |
25 |
Correct |
13 ms |
12152 KB |
Output is correct |
26 |
Correct |
13 ms |
12088 KB |
Output is correct |
27 |
Correct |
13 ms |
12152 KB |
Output is correct |
28 |
Correct |
13 ms |
12152 KB |
Output is correct |
29 |
Correct |
13 ms |
12152 KB |
Output is correct |
30 |
Correct |
13 ms |
12152 KB |
Output is correct |
31 |
Correct |
14 ms |
12152 KB |
Output is correct |
32 |
Correct |
14 ms |
12280 KB |
Output is correct |
33 |
Correct |
14 ms |
12280 KB |
Output is correct |
34 |
Correct |
14 ms |
12284 KB |
Output is correct |
35 |
Correct |
14 ms |
12280 KB |
Output is correct |
36 |
Correct |
18 ms |
12280 KB |
Output is correct |
37 |
Correct |
15 ms |
12280 KB |
Output is correct |
38 |
Correct |
16 ms |
12232 KB |
Output is correct |
39 |
Correct |
14 ms |
12280 KB |
Output is correct |
40 |
Correct |
14 ms |
12252 KB |
Output is correct |
41 |
Correct |
14 ms |
12280 KB |
Output is correct |
42 |
Correct |
14 ms |
12280 KB |
Output is correct |
43 |
Correct |
14 ms |
12280 KB |
Output is correct |
44 |
Correct |
14 ms |
12280 KB |
Output is correct |
45 |
Correct |
14 ms |
12280 KB |
Output is correct |
46 |
Correct |
29 ms |
14840 KB |
Output is correct |
47 |
Correct |
39 ms |
17272 KB |
Output is correct |
48 |
Correct |
43 ms |
17784 KB |
Output is correct |
49 |
Correct |
40 ms |
18168 KB |
Output is correct |
50 |
Correct |
40 ms |
18552 KB |
Output is correct |
51 |
Correct |
47 ms |
17976 KB |
Output is correct |
52 |
Correct |
29 ms |
15096 KB |
Output is correct |
53 |
Correct |
21 ms |
13944 KB |
Output is correct |
54 |
Correct |
39 ms |
17272 KB |
Output is correct |
55 |
Correct |
47 ms |
18348 KB |
Output is correct |
56 |
Correct |
35 ms |
18040 KB |
Output is correct |
57 |
Correct |
34 ms |
17268 KB |
Output is correct |
58 |
Correct |
41 ms |
17644 KB |
Output is correct |
59 |
Correct |
36 ms |
18168 KB |
Output is correct |
60 |
Correct |
37 ms |
18168 KB |
Output is correct |
61 |
Correct |
88 ms |
25840 KB |
Output is correct |
62 |
Correct |
108 ms |
30796 KB |
Output is correct |
63 |
Correct |
136 ms |
37400 KB |
Output is correct |
64 |
Correct |
160 ms |
42232 KB |
Output is correct |
65 |
Correct |
151 ms |
44372 KB |
Output is correct |
66 |
Correct |
178 ms |
41848 KB |
Output is correct |
67 |
Correct |
151 ms |
35864 KB |
Output is correct |
68 |
Correct |
83 ms |
24016 KB |
Output is correct |
69 |
Correct |
165 ms |
37880 KB |
Output is correct |
70 |
Correct |
155 ms |
43260 KB |
Output is correct |
71 |
Correct |
123 ms |
41464 KB |
Output is correct |
72 |
Correct |
128 ms |
38816 KB |
Output is correct |
73 |
Correct |
134 ms |
41324 KB |
Output is correct |
74 |
Correct |
137 ms |
42832 KB |
Output is correct |
75 |
Correct |
136 ms |
42848 KB |
Output is correct |