Language: C++

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;
int n;
long long c;
vector<long long> h;
long long dp[202020] = {0};

template <typename T> class ConvecHullTrick {
private:
  // 直線群(配列)
  std::vector<std::pair<T, T>> lines;
  // 最小値(最大値)を求めるxが単調であるか
  bool isMonotonicX;
  // 最小/最大を判断する関数
  std::function<bool(T l, T r)> comp;

public:
  // コンストラクタ ( クエリが単調であった場合はflag = trueとする )
  ConvecHullTrick(bool flagX = false, std::function<bool(T l, T r)> compFunc =
                                          [](T l, T r) { return l >= r; })
      : isMonotonicX(flagX), comp(compFunc) {
    lines.emplace_back(0, 0);
  };

  // 直線l1, l2, l3のうちl2が不必要であるかどうか
  bool check(std::pair<T, T> l1, std::pair<T, T> l2, std::pair<T, T> l3) {
    if (l1 < l3)
      std::swap(l1, l3);
    return (l3.second - l2.second) * (l2.first - l1.first) >=
           (l2.second - l1.second) * (l3.first - l2.first);
  }

  // 直線y=ax+bを追加する
  void add(T a, T b) {
    std::pair<T, T> line(a, b);
    while (lines.size() >= 2 && check(*(lines.end() - 2), lines.back(), line))
      lines.pop_back();
    lines.emplace_back(line);
  }

  // i番目の直線f_i(x)に対するxの時の値を返す
  T f(int i, T x) { return lines[i].first * x + lines[i].second; }

  // i番目の直線f_i(x)に対するxの時の値を返す
  T f(std::pair<T, T> line, T x) { return line.first * x + line.second; }

  // 直線群の中でxの時に最小(最大)となる値を返す
  T get(T x) {
    // 最小値(最大値)クエリにおけるxが単調
    if (isMonotonicX) {
      static int head = 0;
      while (lines.size() - head >= 2 && comp(f(head, x), f(head + 1, x)))
        ++head;
      return f(head, x);
    } else {
      int low = -1, high = lines.size() - 1;
      while (high - low > 1) {
        int mid = (high + low) / 2;
        (comp(f(mid, x), f(mid + 1, x)) ? low : high) = mid;
      }
      return f(high, x);
    }
  }
};
// ref: http://satanic0258.hatenablog.com/entry/2016/08/16/181331

int main() {
  cin >> n >> c;
  h.resize(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  ConvecHullTrick<long long> q(true);
  dp[0] = 0;
  q.add(-2 * h[0], h[0] * h[0] + dp[0]);
  for (int i = 1; i < n; i++) {
    dp[i] = q.get(h[i]) + h[i] * h[i] + c;
    q.add(-2 * h[i], h[i] * h[i] + dp[i]);
  }
  cout << dp[n - 1] << endl;
  return 0;
}


Compiler output:
a.cc:26:8: error: 'function' in namespace 'std' does not name a template type
   26 |   std::function<bool(T l, T r)> comp;
      |        ^~~~~~~~
a.cc:12:1: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>'
   11 | #include <vector>
  +++ |+#include <functional>
   12 | 
a.cc:30:39: error: 'std::function' has not been declared
   30 |   ConvecHullTrick(bool flagX = false, std::function<bool(T l, T r)> compFunc =
      |                                       ^~~
a.cc:30:52: error: expected ',' or '...' before '<' token
   30 |   ConvecHullTrick(bool flagX = false, std::function<bool(T l, T r)> compFunc =
      |                                                    ^
a.cc:30:39: error: default argument missing for parameter 2 of 'ConvecHullTrick<T>::ConvecHullTrick(bool, int)'
   30 |   ConvecHullTrick(bool flagX = false, std::function<bool(T l, T r)> compFunc =
      |                                       ^~~~~~~~~~~~~
a.cc:30:24: note: ...following parameter 1 which has a default argument
   30 |   ConvecHullTrick(bool flagX = false, std::function<bool(T l, T r)> compFunc =
      |                   ~~~~~^~~~~~~~~~~~~
a.cc: In constructor 'ConvecHullTrick<T>::ConvecHullTrick(bool, int)':
a.cc:32:30: error: class 'ConvecHullTrick<T>' does not have any field named 'comp'
   32 |       : isMonotonicX(flagX), comp(compFunc) {
      |                              ^~~~
a.cc:32:35: error: 'compFunc' was not declared in this scope
   32 |       : isMonotonicX(flagX), comp(compFunc) {
      |                                   ^~~~~~~~
a.cc: In instantiation of 'T ConvecHullTrick<T>::get(T) [with T = long long int]':
a.cc:87:18:   required from here
   87 |     dp[i] = q.get(h[i]) + h[i] * h[i] + c;
      |             ~~~~~^~~~~~
a.cc:63:46: error: 'comp' was not declared in this scope
   63 |       while (lines.size() - head >= 2 && comp(f(head, x), f(head + 1, x)))
      |                                          ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:70:14: error: 'comp' was not declared in this scope
   70 |         (comp(f(mid, x), f(mid + 1, x)) ? low : high) = mid;
      |          ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~