Language: C++

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mp make_pair
const ll INF = 1e18;
typedef pair<ll, ll> pll;

struct Node {
	ll valm;
	ll valp;
	ll add;
	
	Node() {}
};

const int N = 2e5 + 10;
Node tree[4 * N];

void build(int tv, int tl, int tr) {
	if (tr - tl == 1) {
		tree[tv].valm = INF - tl;
		tree[tv].valp = INF + tl;
		tree[tv].add = 0;
		return;
	}
	int tm = (tl + tr) / 2;
	build(2 * tv + 1, tl, tm);
	build(2 * tv + 2, tm, tr);
	tree[tv].valm = min(tree[2 * tv + 1].valm, tree[2 * tv + 2].valm);
	tree[tv].valp = min(tree[2 * tv + 1].valp, tree[2 * tv + 2].valp);
	tree[tv].add = 0;
}

void push(int tv, int tl, int tr) {
	tree[tv].valm += tree[tv].add;
	tree[tv].valp += tree[tv].add;
	if (tr - tl > 1) {
		tree[2 * tv + 1].add += tree[tv].add;
		tree[2 * tv + 2].add += tree[tv].add;
	}
	tree[tv].add = 0;
}

void add_num(int tv, int tl, int tr, int l, int r, ll val) {
	if (tr == r && tl == l) {
		tree[tv].add += val;
		push(tv, tl, tr);
		return;
	}
	push(tv, tl, tr);
	int tm = (tl + tr) / 2;
	if (l < tm)
		add_num(2 * tv + 1, tl, tm, l, min(r, tm), val);
	if (r > tm)
		add_num(2 * tv + 2, tm, tr, max(l, tm), r, val);	
	push(2 * tv + 1, tl, tm);
	push(2 * tv + 2, tm, tr);
	tree[tv].valm = min(tree[2 * tv + 1].valm, tree[2 * tv + 2].valm);
	tree[tv].valp = min(tree[2 * tv + 1].valp, tree[2 * tv + 2].valp);
}

pll get_min(int tv, int tl, int tr, int l, int r) {
	push(tv, tl, tr);
	if (tr == r && tl == l) {
		return pll(tree[tv].valm, tree[tv].valp);
	}
	int tm = (tl + tr) / 2;
	pll res1(INF, INF);
	pll res2(INF, INF);
	if (l < tm) {
		res1 = get_min(2 * tv + 1, tl, tm, l, min(r, tm));
	}
	if (r > tm) {
		res2 = get_min(2 * tv + 2, tm, tr, max(l, tm), r);
	}
	push(2 * tv + 1, tl, tm);
	push(2 * tv + 2, tm, tr);
	return pll(min(res1.first, res2.first), min(res1.second, res2.second));
}

void update_pos(int tv, int tl, int tr, int pos, int val) {
	push(tv, tl, tr);
	if (tr - tl == 1) {
		tree[tv].valm = val - tl;
		tree[tv].valp = val + tl;
		return;
	}
	int tm = (tl + tr) / 2;
	if (pos < tm)
		update_pos(2 * tv + 1, tl, tm, pos, val);
	else
		update_pos(2 * tv + 2, tm, tr, pos, val);
	push(2 * tv + 1, tl, tm);
	push(2 * tv + 2, tm, tr);
	tree[tv].valm = min(tree[2 * tv + 1].valm, tree[2 * tv + 2].valm);
	tree[tv].valp = min(tree[2 * tv + 1].valp, tree[2 * tv + 2].valp);
}	

ll get_pos(int tv, int tl, int tr, int pos) {
	push(tv, tl, tr);
	if (tr - tl == 1) 
		return tree[tv].valm + tl;
	int tm = (tl + tr) / 2;
	if (pos < tm)
		return get_pos(2 * tv + 1, tl, tm, pos);
	else
		return get_pos(2 * tv + 2, tm, tr, pos);
}

int 

int main() {
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);	
	int n, q, a, b;
	cin >> n >> q >> a >> b;
	a--; b--;
	build(0, 0, n);
	ll last = b;
	update_pos(0, 0, n, a, 0);
	while (q--) {
		ll x;
		cin >> x;
		x--;
		auto p1 = get_min(0, 0, n, 0, x);
		auto p2 = get_min(0, 0, n, x, n);
		add_num(0, 0, n, 0, n, abs(last - x));
		ll cur_val = get_pos(0, 0, n, last);
		if (min(p1.first + x, p2.second - x) < cur_val)
			update_pos(0, 0, n, last, min(p1.first + x, p2.second - x));
		last = x;
	}
	ll res = INF;
	for (int i = 0; i < n; i++) {
		res = min(res, get_pos(0, 0, n, i));
	}
	cout << res << endl;
	return 0;
}


Compiler output:
a.cc:111:1: error: two or more data types in declaration of 'main'
  111 | int
      | ^~~