Language: C++

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

#define LL                  long long
#define DB                  double
#define ULL                 unsigned long long
#define PII                 pair<int,int>

#define mp                  make_pair
#define fi                  first
#define se                  second
#define psb                 push_back
#define ppb                 pop_back
#define endln               printf("\n")

#define ALL(x)              (x).begin(),(x).end()
#define SZ(x)               (int)(x).size()

#define SETMIN(x)           memset((x), -1, sizeof (x))
#define SETNUL(x)           memset((x),  0, sizeof (x))
#define gc                  getchar_unlocked

#ifndef getchar_unlocked
#define getchar_unlocked    getchar
#endif

const int INF = 1e9 + 5;
const LL INFLL = 1e18+5;
const int MOD = 1e9 + 7;

template <typename T>
void gi(T &ret) {
    ret = 0; char inp = gc(); bool isNeg = 0;
    while (inp < '0' || inp > '9') { 
        if (inp == '-') isNeg = 1; 
        inp = gc();
    }
    while ('0' <= inp && inp <= '9') {
        ret = (ret << 3) + (ret << 1) + (inp - '0');
        inp = gc();
    }
    if (isNeg) ret = -ret;
}

struct SegVal {
    LL a, b;
    LL lazyA, lazyB;

    SegVal() {
        a = b = INFLL;
        lazyA = lazyB = 0;
    }
};

const int MAXA = (1 << 19) + 5;
SegVal segVal[MAXA];

void pushVal(int idx) {
    int lc = (idx << 1) + 1, rc = (idx << 1) + 2;

    if (segVal[idx].lazyA) {
        LL &lazyA = segVal[idx].lazyA;

        segVal[lc].a += lazyA;
        segVal[rc].a += lazyA;

        segVal[lc].lazyA += lazyA;
        segVal[rc].lazyA += lazyA;        

        lazyA = 0;
    }

    if (segVal[idx].lazyB) {
        LL &lazyB = segVal[idx].lazyB;

        segVal[lc].b += lazyB;
        segVal[rc].b += lazyB;

        segVal[lc].lazyB += lazyB;
        segVal[rc].lazyB += lazyB;        

        lazyB = 0;
    }
}

void updateAdd(int idx, int l, int r, int x, int y, LL da, LL db) {
    if (x <= l && r <= y) {
        segVal[idx].a += da;
        segVal[idx].b += db;

        segVal[idx].lazyA += da;
        segVal[idx].lazyB += db;
        return;
    }
    if (l > y || r < x) {
        return;
    }

    pushVal(idx);

    int mid = (l + r) >> 1, lc = (idx << 1) + 1, rc = (idx << 1) + 2;
    updateAdd(lc, l, mid, x, y, da, db);
    updateAdd(rc, mid + 1, r, x, y, da, db);

    segVal[idx].a = min(segVal[lc].a, segVal[rc].a);
    segVal[idx].b = min(segVal[lc].b, segVal[rc].b);
}

void updateVal(int idx, int l, int r, int x, LL a, LL b) {
    if (l == r) {
        segVal[idx].a = min(segVal[idx].a, a);
        segVal[idx].b = min(segVal[idx].b, b);
        return;
    }

    pushVal(idx);

    int mid = (l + r) >> 1, lc = (idx << 1) + 1, rc = (idx << 1) + 2;
    if (x <= mid) updateVal(lc, l, mid, x, a, b);
    else updateVal(rc, mid + 1, r, x, a, b);

    segVal[idx].a = min(segVal[lc].a, segVal[rc].a);
    segVal[idx].b = min(segVal[lc].b, segVal[rc].b);
}

LL query(int idx, int l, int r, int x, int y, int k) {
    if (x <= l && r <= y) {
        if (k == 0) return segVal[idx].a;
        else return segVal[idx].b;
    }
    if (l > y || r < x) {
        return INFLL;
    }

    pushVal(idx);

    int mid = (l + r) >> 1, lc = (idx << 1) + 1, rc = (idx << 1) + 2;
    return min(query(lc, l, mid, x, y, k), query(rc, mid + 1, r, x, y, k));
}

const int MAXN = 2e5 + 5;
int n, m, va, vb;
int val[MAXN];

LL solve() {
    updateVal(0, 1, n, val[0], 0 - val[0], 0 + val[0]);

    for (int i = 2; i <= m + 1; ++i) {
        LL ca = query(0, 1, n, 1, val[i], 0);
        LL cb = query(0, 1, n, val[i], n, 1);
        LL hs = min(ca + val[i], cb - val[i]);

        updateAdd(0, 1, n, 1, n, abs(val[i] - val[i - 1]), abs(val[i] - val[i - 1]));
        updateVal(0, 1, n, val[i - 1], hs - val[i - 1], hs + val[i - 1]);
    }

    LL ans = INFLL;
    for (int i = 1; i <= n; ++i) {
        LL cs = query(0, 1, n, i, i, 0);
        ans = min(ans, cs  + i);
    }

    return ans;
}

long long minimum_time(int N, int M, int A, int B, std::vector<int> X) {
    n = N; m = M;
    val[0] = A; val[1] = B;

    for (int i = 2; i <= m + 1; ++i)
        val[i] = X[i - 2];

    return solve();
}


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