#include <bits/stdc++.h>
using namespace std;
int a[500009];
long long rs[500009];
struct node{
pair<int,int> v;
node *l,*r;
node():v({-1,0}),l(NULL),r(NULL){}
void up(long long s,long long e,long long x,pair<int,int> uv){
long long m = (s+e)/2;
if(s==e){
v = max(v,uv);return;
}
if(x>m){
if(r==NULL)r = new node();
r->up(m+1,e,x,uv);
}
else{
if(l==NULL)l = new node();
l->up(s,m,x,uv);
}
v = {-1,0};
if(r)v = max(v,r->v);
if(l)v = max(v,l->v);
}
pair<int,int> qu(long long s,long long e,long long x,long long y){
long long m = (s+e)/2;
if(s==x&&e==y)return v;
if(x>m){
if(r)return r->qu(m+1,e,x,y);
else return {-1,0};
}
if(y<=m){
if(l)return l->qu(s,m,x,y);
else return {-1,0};
}
pair<int,int> qv = {-1,0};
if(r)qv = max(qv,r->qu(m+1,e,m+1,y));
if(l)qv = max(qv,l->qu(s,m,x,m));
return qv;
}
}*root;
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
rs[i+1]=rs[i]+a[i];
}
root = new node();
root->up(0,(long long)5e14,0,{0,0});
pair<int,long long> dp;
for(int i=1;i<=n;i++){
pair<int,int> res = root->qu(0,(long long)5e14,0,rs[i]);
dp = {res.first,rs[res.second] - rs[i]};
dp.first++;
root->up(0,(long long)5e14,rs[i] - dp.second,{dp.first,i});
//cout << dp[i].first << ' ' << dp[i].second << '\n';
// cout << res.first << ' ' << res.second.first << ' ' << res.second.second << '\n';
}
printf("%d", dp.first);
}
Compilation message
segments.cpp: In function 'int main()':
segments.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
segments.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 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 |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
6 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 |
7 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 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 |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
6 ms |
376 KB |
Output is correct |
16 |
Correct |
6 ms |
504 KB |
Output is correct |
17 |
Correct |
6 ms |
632 KB |
Output is correct |
18 |
Correct |
6 ms |
760 KB |
Output is correct |
19 |
Correct |
6 ms |
760 KB |
Output is correct |
20 |
Correct |
7 ms |
760 KB |
Output is correct |
21 |
Correct |
6 ms |
760 KB |
Output is correct |
22 |
Correct |
7 ms |
760 KB |
Output is correct |
23 |
Correct |
6 ms |
624 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
7 ms |
760 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
6 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
6 ms |
504 KB |
Output is correct |
30 |
Correct |
7 ms |
504 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 |
7 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 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 |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
6 ms |
376 KB |
Output is correct |
16 |
Correct |
6 ms |
504 KB |
Output is correct |
17 |
Correct |
6 ms |
632 KB |
Output is correct |
18 |
Correct |
6 ms |
760 KB |
Output is correct |
19 |
Correct |
6 ms |
760 KB |
Output is correct |
20 |
Correct |
7 ms |
760 KB |
Output is correct |
21 |
Correct |
6 ms |
760 KB |
Output is correct |
22 |
Correct |
7 ms |
760 KB |
Output is correct |
23 |
Correct |
6 ms |
624 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
7 ms |
760 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
6 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
6 ms |
504 KB |
Output is correct |
30 |
Correct |
7 ms |
504 KB |
Output is correct |
31 |
Correct |
9 ms |
1912 KB |
Output is correct |
32 |
Correct |
11 ms |
2424 KB |
Output is correct |
33 |
Correct |
10 ms |
2808 KB |
Output is correct |
34 |
Correct |
10 ms |
2680 KB |
Output is correct |
35 |
Correct |
12 ms |
3192 KB |
Output is correct |
36 |
Correct |
11 ms |
3192 KB |
Output is correct |
37 |
Correct |
10 ms |
2808 KB |
Output is correct |
38 |
Correct |
10 ms |
2296 KB |
Output is correct |
39 |
Correct |
7 ms |
760 KB |
Output is correct |
40 |
Correct |
11 ms |
3064 KB |
Output is correct |
41 |
Correct |
7 ms |
760 KB |
Output is correct |
42 |
Correct |
8 ms |
1144 KB |
Output is correct |
43 |
Correct |
7 ms |
632 KB |
Output is correct |
44 |
Correct |
9 ms |
1528 KB |
Output is correct |
45 |
Correct |
9 ms |
1528 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 |
7 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 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 |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
6 ms |
376 KB |
Output is correct |
16 |
Correct |
6 ms |
504 KB |
Output is correct |
17 |
Correct |
6 ms |
632 KB |
Output is correct |
18 |
Correct |
6 ms |
760 KB |
Output is correct |
19 |
Correct |
6 ms |
760 KB |
Output is correct |
20 |
Correct |
7 ms |
760 KB |
Output is correct |
21 |
Correct |
6 ms |
760 KB |
Output is correct |
22 |
Correct |
7 ms |
760 KB |
Output is correct |
23 |
Correct |
6 ms |
624 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
7 ms |
760 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
6 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
6 ms |
504 KB |
Output is correct |
30 |
Correct |
7 ms |
504 KB |
Output is correct |
31 |
Correct |
9 ms |
1912 KB |
Output is correct |
32 |
Correct |
11 ms |
2424 KB |
Output is correct |
33 |
Correct |
10 ms |
2808 KB |
Output is correct |
34 |
Correct |
10 ms |
2680 KB |
Output is correct |
35 |
Correct |
12 ms |
3192 KB |
Output is correct |
36 |
Correct |
11 ms |
3192 KB |
Output is correct |
37 |
Correct |
10 ms |
2808 KB |
Output is correct |
38 |
Correct |
10 ms |
2296 KB |
Output is correct |
39 |
Correct |
7 ms |
760 KB |
Output is correct |
40 |
Correct |
11 ms |
3064 KB |
Output is correct |
41 |
Correct |
7 ms |
760 KB |
Output is correct |
42 |
Correct |
8 ms |
1144 KB |
Output is correct |
43 |
Correct |
7 ms |
632 KB |
Output is correct |
44 |
Correct |
9 ms |
1528 KB |
Output is correct |
45 |
Correct |
9 ms |
1528 KB |
Output is correct |
46 |
Correct |
103 ms |
35960 KB |
Output is correct |
47 |
Correct |
137 ms |
40824 KB |
Output is correct |
48 |
Correct |
210 ms |
82168 KB |
Output is correct |
49 |
Correct |
210 ms |
88312 KB |
Output is correct |
50 |
Correct |
246 ms |
97912 KB |
Output is correct |
51 |
Correct |
224 ms |
96120 KB |
Output is correct |
52 |
Correct |
109 ms |
48248 KB |
Output is correct |
53 |
Correct |
67 ms |
29176 KB |
Output is correct |
54 |
Correct |
95 ms |
13048 KB |
Output is correct |
55 |
Correct |
220 ms |
93072 KB |
Output is correct |
56 |
Correct |
146 ms |
42744 KB |
Output is correct |
57 |
Correct |
136 ms |
35320 KB |
Output is correct |
58 |
Correct |
148 ms |
39032 KB |
Output is correct |
59 |
Correct |
172 ms |
55416 KB |
Output is correct |
60 |
Correct |
176 ms |
55032 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 |
7 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 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 |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
6 ms |
376 KB |
Output is correct |
16 |
Correct |
6 ms |
504 KB |
Output is correct |
17 |
Correct |
6 ms |
632 KB |
Output is correct |
18 |
Correct |
6 ms |
760 KB |
Output is correct |
19 |
Correct |
6 ms |
760 KB |
Output is correct |
20 |
Correct |
7 ms |
760 KB |
Output is correct |
21 |
Correct |
6 ms |
760 KB |
Output is correct |
22 |
Correct |
7 ms |
760 KB |
Output is correct |
23 |
Correct |
6 ms |
624 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
7 ms |
760 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
6 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
6 ms |
504 KB |
Output is correct |
30 |
Correct |
7 ms |
504 KB |
Output is correct |
31 |
Correct |
9 ms |
1912 KB |
Output is correct |
32 |
Correct |
11 ms |
2424 KB |
Output is correct |
33 |
Correct |
10 ms |
2808 KB |
Output is correct |
34 |
Correct |
10 ms |
2680 KB |
Output is correct |
35 |
Correct |
12 ms |
3192 KB |
Output is correct |
36 |
Correct |
11 ms |
3192 KB |
Output is correct |
37 |
Correct |
10 ms |
2808 KB |
Output is correct |
38 |
Correct |
10 ms |
2296 KB |
Output is correct |
39 |
Correct |
7 ms |
760 KB |
Output is correct |
40 |
Correct |
11 ms |
3064 KB |
Output is correct |
41 |
Correct |
7 ms |
760 KB |
Output is correct |
42 |
Correct |
8 ms |
1144 KB |
Output is correct |
43 |
Correct |
7 ms |
632 KB |
Output is correct |
44 |
Correct |
9 ms |
1528 KB |
Output is correct |
45 |
Correct |
9 ms |
1528 KB |
Output is correct |
46 |
Correct |
103 ms |
35960 KB |
Output is correct |
47 |
Correct |
137 ms |
40824 KB |
Output is correct |
48 |
Correct |
210 ms |
82168 KB |
Output is correct |
49 |
Correct |
210 ms |
88312 KB |
Output is correct |
50 |
Correct |
246 ms |
97912 KB |
Output is correct |
51 |
Correct |
224 ms |
96120 KB |
Output is correct |
52 |
Correct |
109 ms |
48248 KB |
Output is correct |
53 |
Correct |
67 ms |
29176 KB |
Output is correct |
54 |
Correct |
95 ms |
13048 KB |
Output is correct |
55 |
Correct |
220 ms |
93072 KB |
Output is correct |
56 |
Correct |
146 ms |
42744 KB |
Output is correct |
57 |
Correct |
136 ms |
35320 KB |
Output is correct |
58 |
Correct |
148 ms |
39032 KB |
Output is correct |
59 |
Correct |
172 ms |
55416 KB |
Output is correct |
60 |
Correct |
176 ms |
55032 KB |
Output is correct |
61 |
Correct |
504 ms |
165308 KB |
Output is correct |
62 |
Correct |
574 ms |
158688 KB |
Output is correct |
63 |
Correct |
692 ms |
204372 KB |
Output is correct |
64 |
Runtime error |
683 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
65 |
Halted |
0 ms |
0 KB |
- |