답안 #343578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
343578 2021-01-04T08:47:47 Z _ani K개의 묶음 (IZhO14_blocks) C++17
컴파일 오류
0 ms 0 KB
#define BUGO(x) cerr << #x << " = " << (x) << '\n';
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
using ll = long long;
ll dp[100'002][102], a[100'002];
ll mn[4 * 100'002][102];
struct el {
    ll x; int ind;
};
bool operator<(const el& a, const el& b) {
    return a.x < b.x;
}
void Add(int v, int vl, int vr, int k, int pos) {
    if(vl==vr){
        mn[v][k] = dp[pos][k];
        return;
    }
    int m = (vl + vr) / 2;
    if(pos <= m)
        Add(v * 2, vl, m, k, pos);
    else Add(v * 2 + 1, m + 1, vr, k, pos);
    mn[v][k] = min(mn[v * 2][k], mn[v * 2 + 1][k]);
}
ll Mn(int v, int vl, int vr, int k, int l, int r){
    if(vl == l && vr == r){
        return mn[v][k];
    }
    int m = (vl + vr) / 2;
    ll res = 1'000'000'000'000'000'000;
    if(l <= m) res = min(res, Mn(v * 2, vl, m, k, l, min(r, m)));
    if(r > m) res = min(res, Mn(v * 2 + 1, m + 1, vr, k, max(l, m + 1), r));
    return res;
}
stack <el> x;
int main()
{
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	Build(1, 1, n);
	for (int i = 1; i <= n; i++)
		for (int curk = 1; curk <= k; curk++)
			dp[i][curk] = 1'000'000'000'000'000'000;
	for (int i = 1; i <= n; i++)
		for (int curk = 1; curk <= k; curk++) {
               el prev = {1'000'000'000'000'000'000, 0};
               while(!x.empty() && x.top().x < a[i])
                    x.pop();
               if(!x.empty()) prev = x.top();
               x.push({a[i], i});
               dp[i][curk] = min(prev, Mn(1, 0, n, k - 1, prev.ind, i - 1) + a[i]);
			   Add(1, 1, n, curk, i);
			}
	/*for (int i = 1; i <= n; i++)
	{
		for (int curk = 0; curk <= k; curk++)
			cerr << dp[i][curk] << ' ';
		cerr << '\n';
	}*/
	cout << dp[n][k] << '\n';
	return 0;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:43:2: error: 'Build' was not declared in this scope
   43 |  Build(1, 1, n);
      |  ^~~~~
blocks.cpp:54:82: error: no matching function for call to 'min(el&, ll)'
   54 |                dp[i][curk] = min(prev, Mn(1, 0, n, k - 1, prev.ind, i - 1) + a[i]);
      |                                                                                  ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from blocks.cpp:2:
/usr/include/c++/9/bits/stl_algobase.h:198:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  198 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:198:5: note:   template argument deduction/substitution failed:
blocks.cpp:54:82: note:   deduced conflicting types for parameter 'const _Tp' ('el' and 'll' {aka 'long long int'})
   54 |                dp[i][curk] = min(prev, Mn(1, 0, n, k - 1, prev.ind, i - 1) + a[i]);
      |                                                                                  ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from blocks.cpp:2:
/usr/include/c++/9/bits/stl_algobase.h:246:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  246 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:246:5: note:   template argument deduction/substitution failed:
blocks.cpp:54:82: note:   deduced conflicting types for parameter 'const _Tp' ('el' and 'll' {aka 'long long int'})
   54 |                dp[i][curk] = min(prev, Mn(1, 0, n, k - 1, prev.ind, i - 1) + a[i]);
      |                                                                                  ^
In file included from /usr/include/c++/9/algorithm:62,
                 from blocks.cpp:3:
/usr/include/c++/9/bits/stl_algo.h:3444:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3444 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3444:5: note:   template argument deduction/substitution failed:
blocks.cpp:54:82: note:   'el' is not derived from 'std::initializer_list<_Tp>'
   54 |                dp[i][curk] = min(prev, Mn(1, 0, n, k - 1, prev.ind, i - 1) + a[i]);
      |                                                                                  ^
In file included from /usr/include/c++/9/algorithm:62,
                 from blocks.cpp:3:
/usr/include/c++/9/bits/stl_algo.h:3450:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3450 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
blocks.cpp:54:82: note:   'el' is not derived from 'std::initializer_list<_Tp>'
   54 |                dp[i][curk] = min(prev, Mn(1, 0, n, k - 1, prev.ind, i - 1) + a[i]);
      |                                                                                  ^