Submission #524243

# Submission time Handle Problem Language Result Execution time Memory
524243 2022-02-08T21:12:10 Z inluminas Bigger segments (IZhO19_segments) C++17
100 / 100
244 ms 25200 KB
#include"bits/stdc++.h"
using namespace std;
 
#define ll long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false)
#define inf LLONG_MAX

const int lmt=5e5+5;
ll tree[4*lmt];

void update(int at,int L,int R,int pos,ll val){
  if(L==R){
    tree[at]=val;
    return;
  }
  int mid=(L+R)>>1;
  if(pos<=mid) update(at*2,L,mid,pos,val);
  else update(at*2+1,mid+1,R,pos,val);
  tree[at]=max(tree[at*2],tree[at*2+1]);
}

int find(int at,int L,int R,int l,int r,ll u){
  if(r<L || R<l || r<l) return 0;
  int mid=(L+R)>>1;
  if(l<=L && R<=r){
    if(L==R){
      if(tree[at]<u) return 0;
      return L;
    }

    if(tree[at*2+1]>=u) return find(at*2+1,mid+1,R,l,r,u);
    else if(tree[at*2]>=u) return find(at*2,L,mid,l,r,u);
    else return 0;
  }
  int y=find(at*2+1,mid+1,R,l,r,u);
  if(y) return y;
  return find(at*2,L,mid,l,r,u);
}

int main(){
  fastio;

  int n;
  cin>>n;

  ll pre[n+1],dp[n+1],ans[n+1];
  pre[0]=0;

  for(int i=1;i<=n;i++){
    ll x;
    cin>>x;
    pre[i]=pre[i-1]+x;
    update(1,1,n,i,-1e14);
  } 

  ans[0]=0;

  for(int i=1;i<=n;i++){
    int idx=find(1,1,n,1,i,pre[n]-pre[i]);

    dp[i]=pre[i]-pre[idx],ans[i]=ans[idx]+1;

    update(1,1,n,i,pre[n]-pre[i]-dp[i]);
  }

  cout<<ans[n]<<endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 316 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 316 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 316 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 0 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 316 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 316 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 0 ms 320 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 2 ms 448 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 2 ms 460 KB Output is correct
35 Correct 2 ms 460 KB Output is correct
36 Correct 2 ms 460 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 3 ms 460 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 2 ms 452 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 316 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 316 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 0 ms 320 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 2 ms 448 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 2 ms 460 KB Output is correct
35 Correct 2 ms 460 KB Output is correct
36 Correct 2 ms 460 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 3 ms 460 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 2 ms 452 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 1 ms 460 KB Output is correct
46 Correct 37 ms 5092 KB Output is correct
47 Correct 42 ms 5160 KB Output is correct
48 Correct 42 ms 5468 KB Output is correct
49 Correct 41 ms 5612 KB Output is correct
50 Correct 40 ms 5568 KB Output is correct
51 Correct 45 ms 5664 KB Output is correct
52 Correct 22 ms 2884 KB Output is correct
53 Correct 13 ms 1740 KB Output is correct
54 Correct 41 ms 4880 KB Output is correct
55 Correct 45 ms 5568 KB Output is correct
56 Correct 37 ms 5060 KB Output is correct
57 Correct 38 ms 5088 KB Output is correct
58 Correct 38 ms 5060 KB Output is correct
59 Correct 37 ms 5256 KB Output is correct
60 Correct 40 ms 5228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 316 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 316 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 0 ms 320 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 2 ms 448 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 2 ms 460 KB Output is correct
35 Correct 2 ms 460 KB Output is correct
36 Correct 2 ms 460 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 3 ms 460 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 2 ms 452 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 1 ms 460 KB Output is correct
46 Correct 37 ms 5092 KB Output is correct
47 Correct 42 ms 5160 KB Output is correct
48 Correct 42 ms 5468 KB Output is correct
49 Correct 41 ms 5612 KB Output is correct
50 Correct 40 ms 5568 KB Output is correct
51 Correct 45 ms 5664 KB Output is correct
52 Correct 22 ms 2884 KB Output is correct
53 Correct 13 ms 1740 KB Output is correct
54 Correct 41 ms 4880 KB Output is correct
55 Correct 45 ms 5568 KB Output is correct
56 Correct 37 ms 5060 KB Output is correct
57 Correct 38 ms 5088 KB Output is correct
58 Correct 38 ms 5060 KB Output is correct
59 Correct 37 ms 5256 KB Output is correct
60 Correct 40 ms 5228 KB Output is correct
61 Correct 197 ms 22100 KB Output is correct
62 Correct 207 ms 22092 KB Output is correct
63 Correct 223 ms 22596 KB Output is correct
64 Correct 225 ms 24864 KB Output is correct
65 Correct 208 ms 25092 KB Output is correct
66 Correct 244 ms 25200 KB Output is correct
67 Correct 181 ms 21724 KB Output is correct
68 Correct 89 ms 10976 KB Output is correct
69 Correct 220 ms 21392 KB Output is correct
70 Correct 244 ms 25124 KB Output is correct
71 Correct 195 ms 22104 KB Output is correct
72 Correct 215 ms 22596 KB Output is correct
73 Correct 206 ms 23160 KB Output is correct
74 Correct 204 ms 23492 KB Output is correct
75 Correct 203 ms 23488 KB Output is correct