Language: C++

#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define INF (1LL << 61)

#define MAXN (400410)

ll t[MAXN];

#define N (1 << 17)

ll tt[N + N];

ll mymin(int l, int r) {
	ll ret = INF;
	l += N;
	r += N;
	while (l <= r) {
		ret = min(ret, tt[l]);
		ret = min(ret, tt[r]);
		l >>= 1;
		l++;
		r >>= 1;
		r--;
	}
	return ret;
}

ll myup(int pos, int val) {
	pos += N;
	while (pos) {
		tt[pos] = min(tt[pos], val);
		pos >>= 1;
	}
}

ll getmin(int v, int tl, int tr, int l, int r) {
	if (l > r) {
		return INF;
	}
	if ((l == tl) && (r == tr)) {
		return t[v];
	}
	int tm = (tl + tr) / 2;
	ll m1 = getmin(2 * v, tl, tm, l, min(r, tm));
	ll m2 = getmin(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);
	return min(m1, m2);
}

void update(int v, int tl, int tr, int pos, ll new_val) {
	if (tl == tr) {
		t[v] = new_val;
	} else {
		int tm = (tl + tr) / 2;
		if (pos <= tm) {
			update(2 * v, tl, tm, pos, new_val);
		} else {
			update(2 * v + 1, tm + 1, tr, pos, new_val);
		}
		t[v] = min(t[2 * v], t[2 * v + 1]);
	}
}

struct edge {
	int l, r, c;

	edge(int tl = 0, int tr = 0, int tc = 0) {
		l = tl;
		r = tr;
		c = tc;
	}

	void read() {
		cin >> l >> r >> c;
		l--;
		r--;
	}

	bool operator<(const edge & e) const {
		return (l < e.l);
	}

	void print() {
		cerr << l << " " << r << " " << c << endl;
	}
};

int n, m;

edge a[MAXN];
ll ans[MAXN];

ll quickmin(int l, int r) {
	return getmin(1, 0, n - 1, l, r);
}

void quickup(int pos, ll new_val) {
	//cerr << pos << " " << new_val << endl;
	update(1, 0, n - 1, pos, new_val);
}

int main() {
	for (int i = 0; i < MAXN; i++) {
		t[i] = INF;
		ans[i] = INF;
	}
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		a[i].read();	
	}
	sort(a, a + m);
	ans[0] = 0;
	quickup(0, 0);
	//cerr << "here" << endl;
	int curedge = 0;
	for (int i = 0; i < n; i++) {
		ll & curdist = ans[i];
		curdist = quickmin(i, n - 1);
		
		if ((curedge >= m) || (a[curedge].l > i)) {
			continue;
		}
	
		while ((curedge < m) && (a[curedge].l == i)) {
	//		a[curedge].print();
			ll old = quickmin(a[curedge].r, a[curedge].r); 
			ll nnext = curdist + a[curedge].c;
			if (old > nnext) {
				quickup(a[curedge].r, nnext);	
			}
			curedge++;
		}
	}
	ll ret = ans[n - 1];
	if (ret == INF) {
		cout << -1 << endl;
	} else {
		cout << ret << endl;
	}

	return 0;
}


Compiler output:
a.cc: In function 'll myup(int, int)':
a.cc:51:30: error: no matching function for call to 'min(ll&, int&)'
   51 |                 tt[pos] = min(tt[pos], val);
      |                           ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bitset:49,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:51:30: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   51 |                 tt[pos] = min(tt[pos], val);
      |                           ~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:6:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:51:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   51 |                 tt[pos] = min(tt[pos], val);
      |                           ~~~^~~~~~~~~~~~~~
a.cc:54:1: warning: no return statement in function returning non-void [-Wreturn-type]
   54 | }
      | ^