Language: C++

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <bitset>
#include <cassert>

using namespace std;

const int MAXN = 100009;
const long long INF = 1000000000000000000;

struct SegmentTree {
    long long tr_min[4 * MAXN];
    long long tr_add[4 * MAXN];
    int n;

    SegmentTree(int n) : n(n) {
        memset(tr_min, 0, sizeof(tr_min));
        memset(tr_add, 0, sizeof(tr_add));
    }

    void setVal(int id, long long val) {
        setVal(0, 0, n, id, val);
    }

    void setVal(int v, int vl, int vr, int id, long long val) {
        push(v, vl, vr);
        if (vl > id || vr <= id) {
            return;
        }
        if (vr - vl == 1) {
            tr_min[v] = val;
            return;
        }
        int vm = (vl + vr) / 2;
        setVal(2 * v + 1, vl, vm, id, val);
        setVal(2 * v + 2, vm, vr, id, val);
        tr_min[v] = min(tr_min[2 * v + 1], tr_min[2 * v + 2]);
    }

    void addTree(int l, int r, long long val) {
        if (l > r)
            return;
        addTree(0, 0, n, l, r + 1, val);
    }

    long long getMin(int l, int r) {
        return getMax(0, 0, n, l, r + 1);
    }

    void push(int v, int vl, int vr) {
        tr_min[v] += tr_add[v];
        if (vr - vl > 1) {
            tr_add[2 * v + 1] += tr_add[v];
            tr_add[2 * v + 2] += tr_add[v];
        }
        tr_add[v] = 0;
    }

    void addTree(int v, int vl, int vr, int l, int r, long long val) {
        push(v, vl, vr);
        if (vl >= r || l >= vr) {
            return;
        }
        if (vl >= l && vr <= r) {
            tr_add[v] += val;
            push(v, vl, vr);
            return;
        }
        int vm = (vl + vr) / 2;
        addTree(2 * v + 1, vl, vm, l, r, val);
        addTree(2 * v + 2, vm, vr, l, r, val);
        tr_min[v] = min(tr_min[2 * v + 1], tr_min[2 * v + 2]);
    }

    long long getMax(int v, int vl, int vr, int l, int r) {
        push(v, vl, vr);
        if (vl >= r || l >= vr) {
            return INF;
        }
        if (vl >= l && vr <= r) {
            return tr_min[v];
        }
        int vm = (vl + vr) / 2;
        long long max1 = getMax(2 * v + 1, vl, vm, l, r);
        long long max2 = getMax(2 * v + 2, vm, vr, l, r);
        return min(max1, max2);
    }
};

long long x[MAXN];
long long f[MAXN];

int main() {
    int n, e, t;
    cin >> n >> e >> t;
    for (int i = 1; i <= n; ++i)
        cin >> x[i];
    x[0] = 0;
    f[0] = 0;
    SegmentTree tree(n);
    tree.addTree(0, 0, x[1] - x[0] + t);
    int idt = 0;
    for (int i = 1; i <= n; ++i) {
        f[i] = tree.getMin(0, i - 1);
        if (i == n)
            break;
        int pidt = idt;
        while ((x[i + 1] - x[idt + 1]) * 2 > t) {
            tree.setVal(idt, x[i + 1] - x[idt] + (x[i + 1] - x[idt + 1]) * 2);
            ++idt;
        }
        tree.setVal(i, f[i] + x[i + 1] - x[i] + t);
        tree.addTree(idt, i - 1, x[i + 1] - x[i]);
        tree.addTree(0, pidt - 1, 3 * (x[i + 1] - x[i]));
    }
    long long ans = f[n] + e - x[n];
    cout << ans << endl;
}

Compiler output:
a.cc: In constructor 'SegmentTree::SegmentTree(int)':
a.cc:21:9: error: 'memset' was not declared in this scope
   21 |         memset(tr_min, 0, sizeof(tr_min));
      |         ^~~~~~
a.cc:9:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    8 | #include <cassert>
  +++ |+#include <cstring>
    9 |