Submission #173045

# Submission time Handle Problem Language Result Execution time Memory
173045 2020-01-03T08:13:56 Z LinusTorvaldsFan Bigger segments (IZhO19_segments) C++14
100 / 100
917 ms 25208 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int Q=1<<19;
ll tree[2*Q];

ll inf;

void update(int p, ll x) {
	p+=Q;
	tree[p]=x;
	p/=2;
	while(p>0){
		tree[p]=min(tree[2*p],tree[2*p+1]);
		p/=2;
	}
}


ll get(int l, int r) {
	ll ans=inf;
	for(l+=Q,r+=Q;l<r;l>>=1,r>>=1){
		if(l&1)ans=min(ans,tree[l++]);
		if(r&1)ans=min(ans,tree[--r]);
	}
	return ans;
}

int main() {
	memset(tree,60,sizeof(tree));
	inf=tree[0];
	//cout<<inf<<endl;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	vector<int>a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	
	vector<ll>pr(n+1);
	for(int i=0;i<n;i++)pr[i+1]=pr[i]+a[i];
	vector<int>ans(n);
	vector<ll> ans_sum(n);
	ll sum=0;
	for(int i=0;i<n;i++){
		sum+=a[i];
		ans_sum[i]=sum;
		ans[i]=1;
	}
	update(0,ans_sum[0]+pr[1]);
	for(int i=1;i<n;i++){
		if(i>=100){
		int L=0,R=i;
		while(R-L>1){
			int M=(L+R)/2;
			if(get(M,i)<=pr[i+1]){
				L=M;
			} else {
				R=M;
			}
		}
		
		if(pr[i+1]>=ans_sum[L]+pr[L+1]){
			ans[i]=ans[L]+1;
			ans_sum[i]=pr[i+1]-pr[L+1];
		}
		}else{
			for(int j=i-1;j>=0;j--){
			if(pr[i+1]>=ans_sum[j]+pr[j+1]){
				if(ans[i]<ans[j]+1){
					ans[i]=ans[j]+1;
					ans_sum[i]=pr[i+1]-pr[j+1];
					break;
				}
			}
		}
		}
		update(i,ans_sum[i]+pr[i+1]);
	}
	cout<<ans[n-1];
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8568 KB Output is correct
2 Correct 9 ms 8568 KB Output is correct
3 Correct 9 ms 8568 KB Output is correct
4 Correct 9 ms 8568 KB Output is correct
5 Correct 9 ms 8540 KB Output is correct
6 Correct 9 ms 8540 KB Output is correct
7 Correct 9 ms 8572 KB Output is correct
8 Correct 9 ms 8568 KB Output is correct
9 Correct 9 ms 8568 KB Output is correct
10 Correct 9 ms 8568 KB Output is correct
11 Correct 9 ms 8568 KB Output is correct
12 Correct 9 ms 8568 KB Output is correct
13 Correct 9 ms 8568 KB Output is correct
14 Correct 9 ms 8568 KB Output is correct
15 Correct 9 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8568 KB Output is correct
2 Correct 9 ms 8568 KB Output is correct
3 Correct 9 ms 8568 KB Output is correct
4 Correct 9 ms 8568 KB Output is correct
5 Correct 9 ms 8540 KB Output is correct
6 Correct 9 ms 8540 KB Output is correct
7 Correct 9 ms 8572 KB Output is correct
8 Correct 9 ms 8568 KB Output is correct
9 Correct 9 ms 8568 KB Output is correct
10 Correct 9 ms 8568 KB Output is correct
11 Correct 9 ms 8568 KB Output is correct
12 Correct 9 ms 8568 KB Output is correct
13 Correct 9 ms 8568 KB Output is correct
14 Correct 9 ms 8568 KB Output is correct
15 Correct 9 ms 8568 KB Output is correct
16 Correct 9 ms 8568 KB Output is correct
17 Correct 9 ms 8568 KB Output is correct
18 Correct 9 ms 8568 KB Output is correct
19 Correct 9 ms 8568 KB Output is correct
20 Correct 9 ms 8568 KB Output is correct
21 Correct 9 ms 8568 KB Output is correct
22 Correct 9 ms 8568 KB Output is correct
23 Correct 9 ms 8540 KB Output is correct
24 Correct 9 ms 8568 KB Output is correct
25 Correct 10 ms 8568 KB Output is correct
26 Correct 9 ms 8568 KB Output is correct
27 Correct 9 ms 8568 KB Output is correct
28 Correct 9 ms 8628 KB Output is correct
29 Correct 9 ms 8568 KB Output is correct
30 Correct 9 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8568 KB Output is correct
2 Correct 9 ms 8568 KB Output is correct
3 Correct 9 ms 8568 KB Output is correct
4 Correct 9 ms 8568 KB Output is correct
5 Correct 9 ms 8540 KB Output is correct
6 Correct 9 ms 8540 KB Output is correct
7 Correct 9 ms 8572 KB Output is correct
8 Correct 9 ms 8568 KB Output is correct
9 Correct 9 ms 8568 KB Output is correct
10 Correct 9 ms 8568 KB Output is correct
11 Correct 9 ms 8568 KB Output is correct
12 Correct 9 ms 8568 KB Output is correct
13 Correct 9 ms 8568 KB Output is correct
14 Correct 9 ms 8568 KB Output is correct
15 Correct 9 ms 8568 KB Output is correct
16 Correct 9 ms 8568 KB Output is correct
17 Correct 9 ms 8568 KB Output is correct
18 Correct 9 ms 8568 KB Output is correct
19 Correct 9 ms 8568 KB Output is correct
20 Correct 9 ms 8568 KB Output is correct
21 Correct 9 ms 8568 KB Output is correct
22 Correct 9 ms 8568 KB Output is correct
23 Correct 9 ms 8540 KB Output is correct
24 Correct 9 ms 8568 KB Output is correct
25 Correct 10 ms 8568 KB Output is correct
26 Correct 9 ms 8568 KB Output is correct
27 Correct 9 ms 8568 KB Output is correct
28 Correct 9 ms 8628 KB Output is correct
29 Correct 9 ms 8568 KB Output is correct
30 Correct 9 ms 8568 KB Output is correct
31 Correct 11 ms 8696 KB Output is correct
32 Correct 12 ms 8696 KB Output is correct
33 Correct 11 ms 8572 KB Output is correct
34 Correct 11 ms 8696 KB Output is correct
35 Correct 11 ms 8568 KB Output is correct
36 Correct 11 ms 8568 KB Output is correct
37 Correct 11 ms 8572 KB Output is correct
38 Correct 11 ms 8568 KB Output is correct
39 Correct 11 ms 8696 KB Output is correct
40 Correct 11 ms 8568 KB Output is correct
41 Correct 11 ms 8592 KB Output is correct
42 Correct 11 ms 8568 KB Output is correct
43 Correct 11 ms 8568 KB Output is correct
44 Correct 11 ms 8568 KB Output is correct
45 Correct 11 ms 8696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8568 KB Output is correct
2 Correct 9 ms 8568 KB Output is correct
3 Correct 9 ms 8568 KB Output is correct
4 Correct 9 ms 8568 KB Output is correct
5 Correct 9 ms 8540 KB Output is correct
6 Correct 9 ms 8540 KB Output is correct
7 Correct 9 ms 8572 KB Output is correct
8 Correct 9 ms 8568 KB Output is correct
9 Correct 9 ms 8568 KB Output is correct
10 Correct 9 ms 8568 KB Output is correct
11 Correct 9 ms 8568 KB Output is correct
12 Correct 9 ms 8568 KB Output is correct
13 Correct 9 ms 8568 KB Output is correct
14 Correct 9 ms 8568 KB Output is correct
15 Correct 9 ms 8568 KB Output is correct
16 Correct 9 ms 8568 KB Output is correct
17 Correct 9 ms 8568 KB Output is correct
18 Correct 9 ms 8568 KB Output is correct
19 Correct 9 ms 8568 KB Output is correct
20 Correct 9 ms 8568 KB Output is correct
21 Correct 9 ms 8568 KB Output is correct
22 Correct 9 ms 8568 KB Output is correct
23 Correct 9 ms 8540 KB Output is correct
24 Correct 9 ms 8568 KB Output is correct
25 Correct 10 ms 8568 KB Output is correct
26 Correct 9 ms 8568 KB Output is correct
27 Correct 9 ms 8568 KB Output is correct
28 Correct 9 ms 8628 KB Output is correct
29 Correct 9 ms 8568 KB Output is correct
30 Correct 9 ms 8568 KB Output is correct
31 Correct 11 ms 8696 KB Output is correct
32 Correct 12 ms 8696 KB Output is correct
33 Correct 11 ms 8572 KB Output is correct
34 Correct 11 ms 8696 KB Output is correct
35 Correct 11 ms 8568 KB Output is correct
36 Correct 11 ms 8568 KB Output is correct
37 Correct 11 ms 8572 KB Output is correct
38 Correct 11 ms 8568 KB Output is correct
39 Correct 11 ms 8696 KB Output is correct
40 Correct 11 ms 8568 KB Output is correct
41 Correct 11 ms 8592 KB Output is correct
42 Correct 11 ms 8568 KB Output is correct
43 Correct 11 ms 8568 KB Output is correct
44 Correct 11 ms 8568 KB Output is correct
45 Correct 11 ms 8696 KB Output is correct
46 Correct 147 ms 10960 KB Output is correct
47 Correct 153 ms 10972 KB Output is correct
48 Correct 130 ms 10876 KB Output is correct
49 Correct 117 ms 10872 KB Output is correct
50 Correct 113 ms 11000 KB Output is correct
51 Correct 142 ms 10872 KB Output is correct
52 Correct 70 ms 9720 KB Output is correct
53 Correct 44 ms 9336 KB Output is correct
54 Correct 134 ms 10960 KB Output is correct
55 Correct 142 ms 10872 KB Output is correct
56 Correct 107 ms 11000 KB Output is correct
57 Correct 128 ms 10872 KB Output is correct
58 Correct 125 ms 10956 KB Output is correct
59 Correct 108 ms 10872 KB Output is correct
60 Correct 121 ms 10872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8568 KB Output is correct
2 Correct 9 ms 8568 KB Output is correct
3 Correct 9 ms 8568 KB Output is correct
4 Correct 9 ms 8568 KB Output is correct
5 Correct 9 ms 8540 KB Output is correct
6 Correct 9 ms 8540 KB Output is correct
7 Correct 9 ms 8572 KB Output is correct
8 Correct 9 ms 8568 KB Output is correct
9 Correct 9 ms 8568 KB Output is correct
10 Correct 9 ms 8568 KB Output is correct
11 Correct 9 ms 8568 KB Output is correct
12 Correct 9 ms 8568 KB Output is correct
13 Correct 9 ms 8568 KB Output is correct
14 Correct 9 ms 8568 KB Output is correct
15 Correct 9 ms 8568 KB Output is correct
16 Correct 9 ms 8568 KB Output is correct
17 Correct 9 ms 8568 KB Output is correct
18 Correct 9 ms 8568 KB Output is correct
19 Correct 9 ms 8568 KB Output is correct
20 Correct 9 ms 8568 KB Output is correct
21 Correct 9 ms 8568 KB Output is correct
22 Correct 9 ms 8568 KB Output is correct
23 Correct 9 ms 8540 KB Output is correct
24 Correct 9 ms 8568 KB Output is correct
25 Correct 10 ms 8568 KB Output is correct
26 Correct 9 ms 8568 KB Output is correct
27 Correct 9 ms 8568 KB Output is correct
28 Correct 9 ms 8628 KB Output is correct
29 Correct 9 ms 8568 KB Output is correct
30 Correct 9 ms 8568 KB Output is correct
31 Correct 11 ms 8696 KB Output is correct
32 Correct 12 ms 8696 KB Output is correct
33 Correct 11 ms 8572 KB Output is correct
34 Correct 11 ms 8696 KB Output is correct
35 Correct 11 ms 8568 KB Output is correct
36 Correct 11 ms 8568 KB Output is correct
37 Correct 11 ms 8572 KB Output is correct
38 Correct 11 ms 8568 KB Output is correct
39 Correct 11 ms 8696 KB Output is correct
40 Correct 11 ms 8568 KB Output is correct
41 Correct 11 ms 8592 KB Output is correct
42 Correct 11 ms 8568 KB Output is correct
43 Correct 11 ms 8568 KB Output is correct
44 Correct 11 ms 8568 KB Output is correct
45 Correct 11 ms 8696 KB Output is correct
46 Correct 147 ms 10960 KB Output is correct
47 Correct 153 ms 10972 KB Output is correct
48 Correct 130 ms 10876 KB Output is correct
49 Correct 117 ms 10872 KB Output is correct
50 Correct 113 ms 11000 KB Output is correct
51 Correct 142 ms 10872 KB Output is correct
52 Correct 70 ms 9720 KB Output is correct
53 Correct 44 ms 9336 KB Output is correct
54 Correct 134 ms 10960 KB Output is correct
55 Correct 142 ms 10872 KB Output is correct
56 Correct 107 ms 11000 KB Output is correct
57 Correct 128 ms 10872 KB Output is correct
58 Correct 125 ms 10956 KB Output is correct
59 Correct 108 ms 10872 KB Output is correct
60 Correct 121 ms 10872 KB Output is correct
61 Correct 853 ms 20348 KB Output is correct
62 Correct 897 ms 20344 KB Output is correct
63 Correct 917 ms 20352 KB Output is correct
64 Correct 665 ms 24888 KB Output is correct
65 Correct 652 ms 25132 KB Output is correct
66 Correct 825 ms 25080 KB Output is correct
67 Correct 639 ms 21796 KB Output is correct
68 Correct 302 ms 15224 KB Output is correct
69 Correct 790 ms 21496 KB Output is correct
70 Correct 819 ms 25208 KB Output is correct
71 Correct 623 ms 22264 KB Output is correct
72 Correct 762 ms 22648 KB Output is correct
73 Correct 674 ms 23416 KB Output is correct
74 Correct 634 ms 23672 KB Output is correct
75 Correct 657 ms 23852 KB Output is correct