Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <bitset>
#include <numeric>
#include <functional>

using namespace std;

#define INF 1e18

struct RMQ {
	static const int MAX_N = 100000;
	int n;
	vector<long long> dat(2 * MAX_N - 1);
	RMQ() {}
	RMQ(int n_) { init(n_); }
	void init(int n_) {
		n = 1;
		while (n < n_) n *= 2;
		for (int i = 0; i < 2 * n - 1; i++) dat[i] = INF;
	}
	void update(int k, long long a) {
		k += n - 1;
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	long long query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return INF;
		if (a <= l && r <= b) return dat[k];
		else {
			long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return min(vl, vr);
		}
	}
	long long query(int a, int b) {
		return query(a, b, 0, 0, n);
	}

	long long a(int k) {
		return dat[k + n - 1];
	}
};

struct LRC {
	int l, r, c;
	bool operator<(const LRC a) {
		return l < a.l;
	}
};

int main() {
	int n, m; cin >> n >> m;
	vector<LRC> dat(m);
	for (LRC& a : dat) {
		cin >> a.l >> a.r >> a.c;
		--a.l, --a.r;
	}
	sort(dat.begin(), dat.end());
	RMQ segtree(n);
	segtree.update(0, 0);
	for (LRC a : dat) {
		long long mini = segtree.query(a.l, a.r);
		if (mini == INF) continue;
		if (segtree.a(a.r) > mini + a.c) segtree.update(a.r, mini + a.c);
	}
	long long ans = segtree.a(n - 1);
	cout << (ans == INF ? -1 : ans) << endl;

	return 0;
}

Compiler output:
a.cc:27:31: error: expected identifier before numeric constant
   27 |         vector<long long> dat(2 * MAX_N - 1);
      |                               ^
a.cc:27:31: error: expected ',' or '...' before numeric constant
a.cc: In member function 'void RMQ::init(int)':
a.cc:33:56: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   33 |                 for (int i = 0; i < 2 * n - 1; i++) dat[i] = INF;
      |                                                        ^
a.cc: In member function 'void RMQ::update(int, long long int)':
a.cc:37:20: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   37 |                 dat[k] = a;
      |                    ^
a.cc:40:28: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   40 |                         dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
      |                            ^
a.cc:40:41: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   40 |                         dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
      |                                         ^
a.cc:40:57: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   40 |                         dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
      |                                                         ^
a.cc: In member function 'long long int RMQ::query(int, int, int, int, int)':
a.cc:45:49: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   45 |                 if (a <= l && r <= b) return dat[k];
      |                                                 ^
a.cc: In member function 'long long int RMQ::a(int)':
a.cc:57:27: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   57 |                 return dat[k + n - 1];
      |                           ^