Language: C++

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MOD = 1e9+7;
const ll INF = 1e18;
const int N = 2e5+5;
const ll M = 1e6+5;

struct LiChao_min
{
	struct line
	{
		ll a, b;
		line() { a = 0; b = 0; }
		line(ll _a, ll _b) { a = _a; b = _b; }
		ll eval(ll x) { return a*x+b; }
	};

	struct node
	{
		node *l, *r; line f;

		node() { f = line(); l = nullptr; r = nullptr; }
		node(ll a, ll b) { f = line(a, b); l = nullptr; r = nullptr; }
		node(line v) { f = v; l = nullptr; r = nullptr; }
	};

	typedef node* pnode;

	pnode root; int sz;
	void init(int _sz) { sz = _sz + 1; root = nullptr; }

	void add_line(ll a, ll b) { line v = line(a, b); insert(v, -sz, sz, root); }
	int64_t query(ll x) { return query(x, -sz, sz, root); }

	void insert(line &v, ll l, ll r, pnode &nd)
	{
		if(!nd) { nd = new node(v); return; }

		ll trl = nd->f.eval(l), trr = nd->f.eval(r);
		ll vl = v.eval(l), vr = v.eval(r);

		if(trl <= vl && trr <= vr) return;
		if(trl > vl && trr > vr) { nd->f = v; return; }

		ll mid = (l + r) >> 1LL;
		if(trl > vl) swap(nd->f, v);
		if(nd->f.eval(mid) < v.eval(mid)) insert(v, mid + 1, r, nd->r);
		else swap(nd->f, v), insert(v, l, mid, nd->l);
	}

	int64_t query(ll x, ll l, ll r, pnode &nd)
	{
		if(!nd) return INF;
		if(l == r) return nd->f.eval(x);

		ll mid = (l + r) >> 1LL;
		if(mid >= x) return min(nd->f.eval(x), query(x, l, mid, nd->l));
		return min(nd->f.eval(x), query(x, mid + 1, r, nd->r));
	}
};


LiChao_min tree;
int n;
ll c,h[N],dp[N];

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>c;

    for(int i=1;i<=n;i++)cin>>h[i];

    dp[1]=0LL;
    tree.init(M);
    tree.add_line(-2LL*h[1],1LL*h[1]*h[1]);
    //tree.Set(-2LL*h[1],1LL*h[1]*h[1]);

    for(int i=2;i<=n;i++){
        //dp[i]=tree.Get(h[i])+h[i]*h[i]+c;
        dp[i]=tree.query(h[i])+h[i]*h[i]+c;
        //tree.Set(-2LL*h[i],dp[i]+1LL*h[i]*h[i]);
        tree.add_line(-2LL*h[i],dp[i]+1LL*h[i]*h[i]);
    }
    cout<<dp[n];
    return 0;
}


Compiler output:
a.cc: In member function 'int64_t LiChao_min::query(ll, ll, ll, node*&)':
a.cc:59:40: error: no matching function for call to 'min(ll, int64_t)'
   59 |                 if(mid >= x) return min(nd->f.eval(x), query(x, l, mid, nd->l));
      |                                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:59:40: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t' {aka 'long int'})
   59 |                 if(mid >= x) return min(nd->f.eval(x), query(x, l, mid, nd->l));
      |                                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:59:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   59 |                 if(mid >= x) return min(nd->f.eval(x), query(x, l, mid, nd->l));
      |                                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:60:27: error: no matching function for call to 'min(ll, int64_t)'
   60 |                 return min(nd->f.eval(x), query(x, mid + 1, r, nd->r));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:60:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t' {aka 'long int'})
   60 |                 return min(nd->f.eval(x), query(x, mid + 1, r, nd->r));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:60:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   60 |                 return min(nd->f.eval(x), query(x, mid + 1, r, nd->r));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~