답안 #173044

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173044 2020-01-03T08:10:14 Z LinusTorvaldsFan Bigger segments (IZhO19_segments) C++14
13 / 100
10 ms 8700 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;
	}
}


int 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;
}
# 결과 실행 시간 메모리 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 10 ms 8540 KB Output is correct
5 Correct 9 ms 8540 KB Output is correct
6 Correct 9 ms 8568 KB Output is correct
7 Correct 9 ms 8568 KB Output is correct
8 Correct 9 ms 8700 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 8560 KB Output is correct
15 Correct 9 ms 8568 KB Output is correct
# 결과 실행 시간 메모리 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 10 ms 8540 KB Output is correct
5 Correct 9 ms 8540 KB Output is correct
6 Correct 9 ms 8568 KB Output is correct
7 Correct 9 ms 8568 KB Output is correct
8 Correct 9 ms 8700 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 8560 KB Output is correct
15 Correct 9 ms 8568 KB Output is correct
16 Correct 9 ms 8568 KB Output is correct
17 Incorrect 10 ms 8568 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 10 ms 8540 KB Output is correct
5 Correct 9 ms 8540 KB Output is correct
6 Correct 9 ms 8568 KB Output is correct
7 Correct 9 ms 8568 KB Output is correct
8 Correct 9 ms 8700 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 8560 KB Output is correct
15 Correct 9 ms 8568 KB Output is correct
16 Correct 9 ms 8568 KB Output is correct
17 Incorrect 10 ms 8568 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 10 ms 8540 KB Output is correct
5 Correct 9 ms 8540 KB Output is correct
6 Correct 9 ms 8568 KB Output is correct
7 Correct 9 ms 8568 KB Output is correct
8 Correct 9 ms 8700 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 8560 KB Output is correct
15 Correct 9 ms 8568 KB Output is correct
16 Correct 9 ms 8568 KB Output is correct
17 Incorrect 10 ms 8568 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 10 ms 8540 KB Output is correct
5 Correct 9 ms 8540 KB Output is correct
6 Correct 9 ms 8568 KB Output is correct
7 Correct 9 ms 8568 KB Output is correct
8 Correct 9 ms 8700 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 8560 KB Output is correct
15 Correct 9 ms 8568 KB Output is correct
16 Correct 9 ms 8568 KB Output is correct
17 Incorrect 10 ms 8568 KB Output isn't correct
18 Halted 0 ms 0 KB -