#include <bits/stdc++.h>
using namespace std;
int a[500009];
long long rs[500009];
pair<int,int> dp[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});
for(int i=1;i<=n;i++){
pair<int,int> res = root->qu(0,(long long)5e14,0,rs[i]);
dp[i] = {res.first,rs[res.second] - rs[i]};
dp[i].first++;
root->up(0,(long long)5e14,rs[i] - dp[i].second,{dp[i].first,i});
//cout << dp[i].first << ' ' << dp[i].second << '\n';
// cout << res.first << ' ' << res.second.first << ' ' << res.second.second << '\n';
}
printf("%d", dp[n].first);
}
Compilation message
segments.cpp: In function 'int main()':
segments.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
segments.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 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 |
380 KB |
Output is correct |
7 |
Correct |
5 ms |
380 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 |
248 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
380 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 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 |
380 KB |
Output is correct |
7 |
Correct |
5 ms |
380 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 |
248 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
380 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 |
504 KB |
Output is correct |
17 |
Correct |
5 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 |
6 ms |
760 KB |
Output is correct |
21 |
Incorrect |
6 ms |
760 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 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 |
380 KB |
Output is correct |
7 |
Correct |
5 ms |
380 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 |
248 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
380 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 |
504 KB |
Output is correct |
17 |
Correct |
5 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 |
6 ms |
760 KB |
Output is correct |
21 |
Incorrect |
6 ms |
760 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 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 |
380 KB |
Output is correct |
7 |
Correct |
5 ms |
380 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 |
248 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
380 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 |
504 KB |
Output is correct |
17 |
Correct |
5 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 |
6 ms |
760 KB |
Output is correct |
21 |
Incorrect |
6 ms |
760 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 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 |
380 KB |
Output is correct |
7 |
Correct |
5 ms |
380 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 |
248 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
380 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 |
504 KB |
Output is correct |
17 |
Correct |
5 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 |
6 ms |
760 KB |
Output is correct |
21 |
Incorrect |
6 ms |
760 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |