#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
using namespace std;
const int mxn=5e5+5;
ll t[4*mxn]{0};
void build(int i,int l,int r){
if(l==r)return void(t[i]=1e16);
int m=(l+r)>>1;
build(2*i,l,m);build(2*i+1,m+1,r);
t[i]=min(t[2*i],t[2*i+1]);
}
void upd(int i,int l,int r,int idx,ll v){
if(r<idx||l>idx)return;
if(l==r)return void(t[i]=v);
int m=(l+r)>>1;
upd(2*i,l,m,idx,v);upd(2*i+1,m+1,r,idx,v);
t[i]=min(t[2*i],t[2*i+1]);
}
int qr(int i,int l,int r,ll tt){
if(l==r)return l;int m=(l+r)>>1;
if(t[2*i+1]<=tt)return qr(2*i+1,m+1,r,tt);
return qr(2*i,l,m,tt);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n;cin>>n;build(1,0,n);
ll a[n+1]={0};for(int i=1;i<=n;i++)cin>>a[i],a[i]+=a[i-1];
ll dp[n+1]={0};dp[0]=0;upd(1,0,n,0,0);
for(int i=1;i<=n;i++){
int r=qr(1,0,n,a[i]);
dp[i] = dp[r]+1;
upd(1,0,n,i,2*a[i]-a[r]);
}cout<<dp[n];
}
Compilation message
segments.cpp: In function 'int qr(int, int, int, long long int)':
segments.cpp:31:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
31 | if(l==r)return l;int m=(l+r)>>1;
| ^~
segments.cpp:31:22: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
31 | if(l==r)return l;int m=(l+r)>>1;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
504 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
2 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
2 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
508 KB |
Output is correct |
41 |
Correct |
2 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
552 KB |
Output is correct |
43 |
Correct |
2 ms |
500 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
504 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
2 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
2 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
508 KB |
Output is correct |
41 |
Correct |
2 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
552 KB |
Output is correct |
43 |
Correct |
2 ms |
500 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
2 ms |
336 KB |
Output is correct |
46 |
Correct |
20 ms |
4176 KB |
Output is correct |
47 |
Correct |
23 ms |
4176 KB |
Output is correct |
48 |
Correct |
25 ms |
4176 KB |
Output is correct |
49 |
Correct |
27 ms |
4260 KB |
Output is correct |
50 |
Correct |
30 ms |
4176 KB |
Output is correct |
51 |
Correct |
24 ms |
4176 KB |
Output is correct |
52 |
Correct |
13 ms |
3408 KB |
Output is correct |
53 |
Correct |
8 ms |
3152 KB |
Output is correct |
54 |
Correct |
20 ms |
4268 KB |
Output is correct |
55 |
Correct |
34 ms |
4272 KB |
Output is correct |
56 |
Correct |
22 ms |
4176 KB |
Output is correct |
57 |
Correct |
23 ms |
4176 KB |
Output is correct |
58 |
Correct |
23 ms |
4264 KB |
Output is correct |
59 |
Correct |
23 ms |
4344 KB |
Output is correct |
60 |
Correct |
23 ms |
4176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
504 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
2 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
2 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
508 KB |
Output is correct |
41 |
Correct |
2 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
552 KB |
Output is correct |
43 |
Correct |
2 ms |
500 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
2 ms |
336 KB |
Output is correct |
46 |
Correct |
20 ms |
4176 KB |
Output is correct |
47 |
Correct |
23 ms |
4176 KB |
Output is correct |
48 |
Correct |
25 ms |
4176 KB |
Output is correct |
49 |
Correct |
27 ms |
4260 KB |
Output is correct |
50 |
Correct |
30 ms |
4176 KB |
Output is correct |
51 |
Correct |
24 ms |
4176 KB |
Output is correct |
52 |
Correct |
13 ms |
3408 KB |
Output is correct |
53 |
Correct |
8 ms |
3152 KB |
Output is correct |
54 |
Correct |
20 ms |
4268 KB |
Output is correct |
55 |
Correct |
34 ms |
4272 KB |
Output is correct |
56 |
Correct |
22 ms |
4176 KB |
Output is correct |
57 |
Correct |
23 ms |
4176 KB |
Output is correct |
58 |
Correct |
23 ms |
4264 KB |
Output is correct |
59 |
Correct |
23 ms |
4344 KB |
Output is correct |
60 |
Correct |
23 ms |
4176 KB |
Output is correct |
61 |
Correct |
101 ms |
16464 KB |
Output is correct |
62 |
Correct |
102 ms |
16476 KB |
Output is correct |
63 |
Correct |
106 ms |
16592 KB |
Output is correct |
64 |
Correct |
138 ms |
16596 KB |
Output is correct |
65 |
Correct |
128 ms |
16664 KB |
Output is correct |
66 |
Correct |
123 ms |
16464 KB |
Output is correct |
67 |
Correct |
101 ms |
14920 KB |
Output is correct |
68 |
Correct |
58 ms |
7760 KB |
Output is correct |
69 |
Correct |
109 ms |
16596 KB |
Output is correct |
70 |
Correct |
129 ms |
16600 KB |
Output is correct |
71 |
Correct |
118 ms |
16520 KB |
Output is correct |
72 |
Correct |
110 ms |
16492 KB |
Output is correct |
73 |
Correct |
118 ms |
16528 KB |
Output is correct |
74 |
Correct |
138 ms |
16468 KB |
Output is correct |
75 |
Correct |
159 ms |
16456 KB |
Output is correct |