Submission #152830

# Submission time Handle Problem Language Result Execution time Memory
152830 2019-09-09T17:54:53 Z vex K blocks (IZhO14_blocks) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#define maxn 100005
#define INF (int)(1e9 + 77)
using namespace std;
 
int n,k;
int a[maxn];
int dp[maxn][102];
int lv[maxn];
 
 
int minn[maxn][22];
void build(int ind)
{
	for(int d=0;(1<<d)<=n+1;d++)
    {
      	for(int i=0;i+(1<<d)-1<=n;i++)
        {
          	if(d==0)minn[i][0]=dp[i][ind];
          	else
            {
              	minn[i][d]=min( minn[i][d-1], minn[i+(1<<(d-1))][d-1]);
            }
        }
    }
}
 
int query(int lt,int rt)
{
	int d=log2(rt-lt+1);
  	return min( minn[lt][d], minn[rt-(1<<d)+1][d]);
}
 
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	
	stack<int>ms;
	ms.push(0);
	a[0]=INF;
	for(int i=1;i<=n;i++)
	{
		while(!ms.empty())
		{
			int vrh=ms.top();
			if(a[vrh]<=a[i])
			{
				ms.pop();
			}
			else break;
		}
		
		lv[i]=ms.top();
		ms.push(i);
	}
	
	//for(int i=1;i<=n;i++)cout<<lv[i]<<" ";cout<<endl;
	
	for(int i=0;i<=n;i++)
		for(int j=0;j<=k;j++)dp[i][j]=INF;
	dp[0][0]=0;
	
	for(int i=1;i<=n;i++)dp[i][0]=INF;
	for(int j=1;j<=k;j++)
	{
		build(1,0,n,j-1);
		for(int i=1;i<=n;i++)
		{
			dp[i][j]=min( dp[ lv[i] ][j], query(1,0,n,lv[i],i-1)+a[i]);
		}
	}
	
	cout<<dp[n][k];
	return 0;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:72:18: error: too many arguments to function 'void build(int)'
   build(1,0,n,j-1);
                  ^
blocks.cpp:13:6: note: declared here
 void build(int ind)
      ^~~~~
blocks.cpp:75:55: error: too many arguments to function 'int query(int, int)'
    dp[i][j]=min( dp[ lv[i] ][j], query(1,0,n,lv[i],i-1)+a[i]);
                                                       ^
blocks.cpp:28:5: note: declared here
 int query(int lt,int rt)
     ^~~~~