#include using namespace std; #define rep(i,j,n) for(int i=j;i; template using vt = vector; template using vvt = vector>; i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));} i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);} int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; #include #include template class LazySegmentTree { using F = std::function; using G = std::function; using H = std::function; private: int n; std::vector seg; std::vector lazy; const F f; const G g; const H h; const Monoid M1; const OperatorMonoid OM1; void lazyUpdate(int k, int l, int r) { if(lazy[k] == OM1) return; if(2 * k + 1 < 2 * n - 1) { lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]); lazy[2 * k + 2] = h(lazy[2 * k + 2], lazy[k]); } seg[k] = g(seg[k], lazy[k], r - l); lazy[k] = OM1; } public: LazySegmentTree(int sz, const F f, const G g, const H h, const Monoid &M1, const OperatorMonoid &OM1) : f(f), g(g), h(h), M1(M1), OM1(OM1) { n = 1; while(n < sz) n *= 2; seg.resize(2 * n - 1, M1); lazy.resize(2 * n - 1, OM1); } void update(int a, int b, Monoid x, int k = 0, int l = 0, int r = -1) { if(r < 0) r = n; lazyUpdate(k, l, r); if(b <= l || r <= a) return; if(a <= l && r <= b) { lazy[k] = h(lazy[k], x); lazyUpdate(k, l, r); } else { update(a, b, x, 2 * k + 1, l, (l + r) / 2); update(a, b, x, 2 * k + 2, (l + r) / 2, r); seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2]); } } Monoid query(int a, int b, int k = 0, int l = 0, int r = -1) { if(r < 0) r = n; lazyUpdate(k, l, r); if(b <= l || r <= a) return M1; if(a <= l && r <= b) return seg[k]; Monoid vl = query(a, b, 2 * k + 1, l, (l + r) / 2); Monoid vr = query(a, b, 2 * k + 2, (l + r) / 2, r); return f(vl, vr); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, q; cin >> n >> q; vt l(n), r(n), b(n); rep(i, 0, q) cin >> l[i] >> r[i] >> b[i]; rep(i, 0, q) l[i]--; vt idx(q); iota(all(idx), 0); sort(all(idx), [&](const int &i, const int &j){ return b[i] < b[j]; }); LazySegmentTree seg(n, [](int a, int b){ return min(a, b); }, [](int a, int b, int len){ if(a == INF) return b; else if(b == INF) return a; else return max(a, b); }, [](int a, int b){ if(a == INF) return b; else if(b == INF) return a; else return max(a, b); }, INF, INF); rep(i, 0, q) { seg.update(l[idx[i]], r[idx[i]], b[idx[i]]); } rep(i, 0, q) { if(seg.query(l[i], r[i] + 1) != b[i]) return cout << -1 << endl, 0; } rep(i, 0, n) { cout << seg.query(i, i + 1) << " \n"[i == n - 1]; } }