Language: C++

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

#define int long long
typedef pair<int, int> P;
//#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/

// vector
template <typename T>
istream & operator>>(istream & is, vector<T> & vec) {
	for (T& x : vec) is >> x;
	return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
	os << "(" << pair_var.first << ", " << pair_var.second << ")";
	return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
	os << "{";
	for (int i = 0; i < vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
	}
	os << "}";
	return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
	os << "{";
	repi(itr, map_var) {
		os << *itr;
		itr++;
		if (itr != map_var.end()) os << ", ";
		itr--;
	}
	os << "}";
	return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
	os << "{";
	repi(itr, set_var) {
		os << *itr;
		itr++;
		if (itr != set_var.end()) os << ", ";
		itr--;
	}
	os << "}";
	return os;
}

#define DUMPOUT cerr

void dump_func() {
	DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
	DUMPOUT << head;
	if (sizeof...(Tail) > 0) {
		DUMPOUT << ", ";
	}
	dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif

//BEGIN CUT HERE
struct RUP {
	int n;
	vector<int> dat, laz;
	const int def = INT_MAX;
	RUP() {}
	RUP(int n_) { init(n_); }
	void init(int n_) {
		n = 1;
		while (n < n_) n *= 2;
		dat.clear();
		dat.resize(2 * n - 1, def);
		laz.clear();
		laz.resize(2 * n - 1, -1);
	}
	inline void eval(int len, int k) {
		if (laz[k] < 0) return;
		if (k * 2 + 1 < n * 2 - 1) {
			laz[k * 2 + 1] = laz[k];
			laz[k * 2 + 2] = laz[k];
		}
		dat[k] = laz[k];
		laz[k] = -1;
	}
	int update(int a, int b, int x, int k, int l, int r) {
		eval(r - l, k);
		if (r <= a || b <= l) return dat[k];
		if (a <= l && r <= b) return laz[k] = x;
		eval(r - l, k);
		dat[k] = min(update(a, b, x, k * 2 + 1, l, (l + r) / 2),
			update(a, b, x, k * 2 + 2, (l + r) / 2, r));
		return dat[k];
	}
	int query(int a, int b, int k, int l, int r) {
		eval(r - l, k);
		if (r <= a || b <= l) return def;
		if (a <= l && r <= b) return dat[k];
		int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
	void update(int a, int b, int x) {
		update(a, b, x, 0, 0, n);
	}
	int query(int a, int b) {
		return query(a, b, 0, 0, n);
	}
};
//END CUT HERE

signed main() {

	int N, M;
	cin >> N >> M;

	vector<tuple<int, int, int>> X(M);
	vector<int> dist(123456, 0);

	rep(i, M) {
		cin >> get<0>(X[i]) >> get<1>(X[i]) >> get<2>(X[i]);
		get<0>(X[i]);
		get<1>(X[i]);
	}
	sort(X.begin(), X.end());

	cerr << "----" << endl;
	rep(i, M) {
		cerr << get<0>(X[i]) << " " << get<1>(X[i])<< " " << get<2>(X[i]) << endl;
	}


	RUP rup(N+1);
	rup.update(1, 2, 0);
	rep(i, M) {
		int prev_val = rup.query(get<0>(X[i]), get<0>(X[i]) + 1);

		auto it = lower_bound(rup.dat.begin() + rup.dat.size() / 2 + 1, rup.dat.end(), prev_val);

		rup.update(it + 1, get<1>(X[i]) + 1, prev_val + get<2>(X[i]));

		dump(get<0>(X[i]), get<1>(X[i]), get<2>(X[i]), prev_val);
		for (int j = 1; j <= N; j++) cerr << rup.query(j, j + 1) << " ";
		cerr << endl;
	}

	if (rup.query(N - 1, N) == INT_MAX) cout << -1 << endl;
	else cout << rup.query(N - 1, N) << endl;


	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:180:27: error: no matching function for call to 'RUP::update(__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >, std::__tuple_element_t<1, std::tuple<long long int, long long int, long long int> >, long long int)'
  180 |                 rup.update(it + 1, get<1>(X[i]) + 1, prev_val + get<2>(X[i]));
      |                 ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:126:13: note: candidate: 'long long int RUP::update(long long int, long long int, long long int, long long int, long long int, long long int)'
  126 |         int update(int a, int b, int x, int k, int l, int r) {
      |             ^~~~~~
a.cc:126:13: note:   candidate expects 6 arguments, 3 provided
a.cc:143:14: note: candidate: 'void RUP::update(long long int, long long int, long long int)'
  143 |         void update(int a, int b, int x) {
      |              ^~~~~~
a.cc:143:25: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to 'long long int'
  143 |         void update(int a, int b, int x) {
      |                         ^