Language: C++

#include "../template.cpp"

struct LiChaoTree {
    using Line = PLL;
    
    struct Node {
        Line line;
        i128 lx, rx;
        Node *l, *r;
        Node(Line line, i128 lx, i128 rx) : lx(lx), rx(rx), line(line) {}
    };
    
    function<i128(i128, i128)> comp; // maybe min or max
    function<bool(i128, i128)> comp_b;
    i128 inf, max_x, id_ele;
    Line init;
    Node *root;

    LiChaoTree(function<i128(i128, i128)> comp, i128 inf, i128 arg_max_x, i128 id_ele, Line init)
        : comp(comp), init(init), inf(inf), id_ele(id_ele)
    {
        max_x = 1;
        while(max_x < arg_max_x) max_x *= 2;
        comp_b = [&](i128 a, i128 b) { return this->comp(a, b) == a; };
        root = new Node(init, 0, max_x);

    }

    i128 calc_y(Line line, i128 x) {
        i128 a, b;
        tie(a, b) = line;
        return a * x + b; 
    }
    i128 calc_y(Node *node, i128 x) { return calc_y(node->line, x); }
    
    Node* add_line(Line line, Node *node, i128 lx, i128 rx) {
        if(node == nullptr) return new Node(line, lx, rx);

        i128 mx = (lx + rx) / 2;

        bool lcmp = comp_b(calc_y(line, lx), calc_y(node, lx));
        bool mcmp = comp_b(calc_y(line, mx), calc_y(node, mx));
        bool rcmp = comp_b(calc_y(line, rx), calc_y(node, rx));

        if(lcmp && rcmp) {
            node->line = line;
            return node;
        }
        if(!lcmp && !rcmp) return node;
        if(mcmp) {
            swap(line, node->line);
            lcmp = !lcmp;
            rcmp = !rcmp;
        }
        if(lcmp) {
            auto l = node->l;
            node->l = add_line(line, l, lx, mx);
        } else {
            auto r = node->r;
            node->r = add_line(line, r, mx, rx);
        }
        return node;
    }

    Node* add_line_seg(Line line, Node *cur, i128 lx, i128 rx) {
        if(rx <= cur->lx || cur->rx <= lx) return cur;
        if(lx <= cur->lx && cur->rx <= rx) return add_line(line, cur, lx, rx);
        if(cur == nullptr) cur = new Node(init, lx, rx);
        cur->l = add_line_seg(line, cur->l, lx, rx);
        cur->r = add_line_seg(line, cur->r, lx, rx);
        return cur;
    }

    Node* add_line(Line line) { return add_line(line, root, 0, max_x); }

    Node* add_line_seg(Line line, i128 lx, i128 rx) { return add_line_seg(line, root, lx, rx); }

    i128 query(i128 qx) {
        i128 lx = 0, rx = max_x;
        Node *cur = root;
        i128 ret = id_ele;
        while(cur != nullptr) {
            i128 tmp = calc_y(cur, qx);
            ret = comp(ret, tmp);
            if(rx - lx == 1) break;
            i128 mx = (lx + rx) / 2;
            if(lx <= qx && qx < mx) {
                rx = mx;
                cur = cur->l;
            } else {
                lx = mx;
                cur = cur->r;
            }
        }
        return ret;
    }
};

// solution for https://atcoder.jp/contests/dp/tasks/dp_z
const i128 inf = 5e18;
LiChaoTree lct([](i128 a, i128 b) { return min(a, b); }, inf, inf, inf, PLL(inf, inf));

int main() {
    i128 N, C;
    cin >> N >> C;
    V<i128> H(N);
    for(auto &&ele : H) cin >> ele;
    V<i128> dp(N + 1);
    dp[1] = 0;
    lct.add_line(PLL(-2 * H[0],  H[0] * H[0] + C));

    multiset<i128> lset;
    multiset<i128, greater<i128>> gset;
    for(ll i = 1; i < N; i++) {
        lset.insert(H[i]);
        gset.insert(H[i]);
    }

    auto get_range = [&] { return make_pair(*lset.begin(), *gset.begin()); };
    auto del_ele = [&](i128 e) {
        auto lite = lset.find(e);
        auto gite = gset.find(e);
        lset.erase(lite);
        gset.erase(gite);
    };

    for(i128 i = 2; i <= N; i++) {
        i128 h = H[i - 1];
        dp[i] = lct.query(h) + h * h;
        del_ele(h);
        i128 l, r;
        tie(l, r) = get_range();
        lct.add_line(PLL(-2 * h, h * h + C + dp[i]));
    }

    cout << dp[N] << endl;
    return 0;
}


Compiler output:
a.cc:1:10: fatal error: ../template.cpp: No such file or directory
    1 | #include "../template.cpp"
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.