Submission #338901

# Submission time Handle Problem Language Result Execution time Memory
338901 2020-12-24T07:39:47 Z nandonathaniel Bigger segments (IZhO19_segments) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN=3005;
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
int a[MAXN],d[MAXN],A[MAXN],last[MAXN],depth[MAXN],ST[MAXN],EN[MAXN],tmp;
long long dp[MAXN][MAXN],pref[MAXN],tree[4*MAXN],lazy[4*MAXN];
int a[MAXN];

void updatenode(int now,int L,int R,int val){
	tree[now]=((R-L+1))*val;
	lazy[now]=val;
}
 
void pushdown(int now,int L,int R){
	if(lazy[now]==-1)return;
	int mid=(L+R)/2;
	updatenode(2*now,L,mid,lazy[now]);
	updatenode(2*now+1,mid+1,R,lazy[now]);
	lazy[now]=-1;
}
 
int query(int now,int L,int R,int x,int y){
	if(L>=x && R<=y)return tree[now];
	if(L>y || R<x)return 0;
	pushdown(now,L,R);
	int mid=(L+R)/2;
	return query(2*now,L,mid,x,y)+query(2*now+1,mid+1,R,x,y);
}
 
void update(int now,int L,int R,int x,int y,int val){
	if(L>y || R<x)return;
	if(L>=x && R<=y){
		updatenode(now,L,R,val);
		return;
	}
	int mid=(L+R)/2;
	pushdown(now,L,R);
	update(2*now,L,mid,x,y,val);
	update(2*now+1,mid+1,R,x,y,val);
	tree[now]=tree[2*now]+tree[2*now+1];
}
 
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		pref[i]=pref[i-1]+a[i];
	}
	memset(lazy,-1,sizeof(lazy));
	memset(dp,-1,sizeof(dp));
	dp[0][0]=0;
	for(int j=1;j<=n;j++){
		update(1,1,n,j,n,0);
		for(int i=j;i<=n;i++){
			if(dp[i-1][j-1]!=-1){
				long long bil;
				if(dp[i-1][j-1]==0)bil=2*pref[i-1];
				else bil=2*pref[i-1]-pref[dp[i-1][j-1]-1];
				int ki=i,ka=n,res=-1;
				while(ki<=ka){
					int mid=(ki+ka)/2;
					if(pref[mid]>=bil){
						res=mid;
						ka=mid-1;
					}
					else ki=mid+1;
				}
				if(res!=-1)update(1,1,n,res,n,i);
			}
			dp[i][j]=query(1,1,n,i,i);
			if(dp[i][j]==0)dp[i][j]=-1;
		}
	}
	for(int j=n;j>=1;j--){
		if(dp[n][j]!=-1){
			cout << j << '\n';
			break;
		}
	}
	return 0;
}

Compilation message

segments.cpp:5: warning: ignoring #pragma GCC option [-Wunknown-pragmas]
    5 | #pragma GCC option("arch=native","tune=native","no-zero-upper")
      | 
segments.cpp:9:5: error: redefinition of 'int a [3005]'
    9 | int a[MAXN];
      |     ^
segments.cpp:7:5: note: 'int a [3005]' previously declared here
    7 | int a[MAXN],d[MAXN],A[MAXN],last[MAXN],depth[MAXN],ST[MAXN],EN[MAXN],tmp;
      |     ^