#include #pragma region Header using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using i128 = __int128_t; using u128 = __uint128_t; using f64 = double; using f80 = long double; using f128 = __float128; constexpr i32 operator"" _i32(u64 v) { return v; } constexpr i32 operator"" _u32(u64 v) { return v; } constexpr i64 operator"" _i64(u64 v) { return v; } constexpr u64 operator"" _u64(u64 v) { return v; } constexpr f64 operator"" _f64(f80 v) { return v; } constexpr f80 operator"" _f80(f80 v) { return v; } using Istream = std::istream; using Ostream = std::ostream; using Str = std::string; template using Lt = std::less; template using Gt = std::greater; template using IList = std::initializer_list; template using BSet = std::bitset; template using Pair = std::pair; template using Tup = std::tuple; template using Arr = std::array; template using Deq = std::deque; template using Set = std::set; template using MSet = std::multiset; template using USet = std::unordered_set; template using UMSet = std::unordered_multiset; template using Map = std::map; template using MMap = std::multimap; template using UMap = std::unordered_map; template using UMMap = std::unordered_multimap; template using Vec = std::vector; template using Stack = std::stack; template using Queue = std::queue; template using MaxHeap = std::priority_queue; template using MinHeap = std::priority_queue, Gt>; using NSec = std::chrono::nanoseconds; using USec = std::chrono::microseconds; using MSec = std::chrono::milliseconds; using Sec = std::chrono::seconds; template constexpr T LIMMIN = std::numeric_limits::min(); template constexpr T LIMMAX = std::numeric_limits::max(); template constexpr T INF = (LIMMAX - 1) / 2; template constexpr T PI = T{3.141592653589793238462643383279502884}; template constexpr T TEN(const int n) { return n == 0 ? T{1} : TEN(n - 1) * T{10}; } Ostream& operator<<(Ostream& os, i128 v) { bool minus = false; if (v < 0) { minus = true, v = -v; } Str ans; if (v == 0) { ans = "0"; } while (v) { ans.push_back('0' + v % 10), v /= 10; } std::reverse(ans.begin(), ans.end()); return os << (minus ? "-" : "") << ans; } Ostream& operator<<(Ostream& os, u128 v) { Str ans; if (v == 0) { ans = "0"; } while (v) { ans.push_back('0' + v % 10), v /= 10; } std::reverse(ans.begin(), ans.end()); return os << ans; } template bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else { return false; } } template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else { return false; } } template constexpr T floorDiv(T x, T y) { if (y < T{}) { x = -x, y = -y; } return x >= T{} ? x / y : (x - y + 1) / y; } template constexpr T ceilDiv(T x, T y) { if (y < T{}) { x = -x, y = -y; } return x >= T{} ? (x + y - 1) / y : x / y; } template constexpr T modPower(T v, I n, T mod) { T ans = 1 % mod; for (; n > 0; n >>= 1, (v *= v) %= mod) { if (n % 2 == 1) { (ans *= v) %= mod; } } return ans; } template constexpr T power(T v, I n) { T ans = 1; for (; n > 0; n >>= 1, v *= v) { if (n % 2 == 1) { ans *= v; } } return ans; } template constexpr T power(T v, I n, const T& e) { T ans = e; for (; n > 0; n >>= 1, v *= v) { if (n % 2 == 1) { ans *= v; } } return ans; } template Vec operator+=(Vec& vs1, const Vec& vs2) { vs1.insert(vs1.end(), vs2.begin(), vs2.end()); return vs1; } template Vec operator+(const Vec& vs1, const Vec& vs2) { auto vs = vs1; vs += vs2; return vs; } template void fillAll(Vec& vs, const T& v) { std::fill(vs.begin(), vs.end(), v); } template> void sortAll(Vec& vs, C comp = C{}) { std::sort(vs.begin(), vs.end(), comp); } template void reverseAll(Vec& vs) { std::reverse(vs.begin(), vs.end()); } template void uniqueAll(Vec& vs) { sortAll(vs); vs.erase(std::unique(vs.begin(), vs.end()), vs.end()); } template V sumAll(const Vec& vs) { return std::accumulate(vs.begin(), vs.end(), V{}); } template int minInd(const Vec& vs) { return std::min_element(vs.begin(), vs.end()) - vs.begin(); } template int maxInd(const Vec& vs) { return std::max_element(vs.begin(), vs.end()) - vs.begin(); } template int lbInd(const Vec& vs, const T& v) { return std::lower_bound(vs.begin(), vs.end(), v) - vs.begin(); } template int ubInd(const Vec& vs, const T& v) { return std::upper_bound(vs.begin(), vs.end(), v) - vs.begin(); } template Vec genVec(int n, F gen) { Vec ans; std::generate_n(std::back_insert_iterator(ans), n, gen); return ans; } Vec iotaVec(int n, int offset = 0) { Vec ans(n); std::iota(ans.begin(), ans.end(), offset); return ans; } template Vec revVec(const Vec& vs) { auto ans = vs; reverseAll(ans); return ans; } constexpr int popcount(const u64 v) { return v ? __builtin_popcountll(v) : 0; } constexpr int log2p1(const u64 v) { return v ? 64 - __builtin_clzll(v) : 0; } constexpr int lsbp1(const u64 v) { return __builtin_ffsll(v); } constexpr int clog(const u64 v) { return v ? log2p1(v - 1) : 0; } constexpr u64 ceil2(const u64 v) { const int l = clog(v); return (l == 64) ? 0_u64 : (1_u64 << l); } constexpr u64 floor2(const u64 v) { return v ? (1_u64 << (log2p1(v) - 1)) : 0_u64; } constexpr bool ispow2(const u64 v) { return (v > 0) and ((v & (v - 1)) == 0); } constexpr bool btest(const u64 mask, const int ind) { return (mask >> ind) & 1_u64; } template struct Fix : F { Fix(F&& f) : F{std::forward(f)} {} template auto operator()(Args&&... args) const { return F::operator()(*this, std::forward(args)...); } }; class irange { private: struct itr { itr(i64 start = 0, i64 step = 1) : m_cnt{start}, m_step{step} {} bool operator!=(const itr& it) const { return m_cnt != it.m_cnt; } int operator*() { return m_cnt; } itr& operator++() { m_cnt += m_step; return *this; } i64 m_cnt, m_step; }; i64 m_start, m_end, m_step; public: irange(i64 start, i64 end, i64 step = 1) { assert(step != 0); const i64 d = std::abs(step); const i64 l = (step > 0 ? start : end); const i64 r = (step > 0 ? end : start); int n = (r - l) / d + ((r - l) % d ? 1 : 0); if (l >= r) { n = 0; } m_start = start; m_end = start + step * n; m_step = step; } itr begin() const { return itr{m_start, m_step}; } itr end() const { return itr{m_end, m_step}; } }; irange rep(int end) { return irange(0, end, 1); } irange per(int rend) { return irange(rend - 1, -1, -1); } #pragma COMMENT("[REFS] Xoshiro: https://prng.di.unimi.it") namespace xoshiro_impl { u64 x; u64 next() { uint64_t z = (x += 0x9e3779b97f4a7c15); z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; z = (z ^ (z >> 27)) * 0x94d049bb133111eb; return z ^ (z >> 31); } } class Xoshiro32 { public: using result_type = u32; using T = result_type; Xoshiro32(T seed = 0) { xoshiro_impl::x = seed; s[0] = xoshiro_impl::next(); s[1] = xoshiro_impl::next(); s[2] = xoshiro_impl::next(); s[3] = xoshiro_impl::next(); } static constexpr T min() { return LIMMIN; } static constexpr T max() { return LIMMAX; } T operator()() { return next(); } private: static constexpr T rotl(const T x, int k) { return (x << k) | (x >> (32 - k)); } T next() { const T ans = rotl(s[1] * 5, 7) * 9; const T t = s[1] << 9; s[2] ^= s[0]; s[3] ^= s[1]; s[1] ^= s[2]; s[0] ^= s[3]; s[2] ^= t; s[3] = rotl(s[3], 11); return ans; } T s[4]; }; class Xoshiro64 { public: using result_type = u64; using T = result_type; Xoshiro64(T seed = 0) { xoshiro_impl::x = seed; s[0] = xoshiro_impl::next(); s[1] = xoshiro_impl::next(); s[2] = xoshiro_impl::next(); s[3] = xoshiro_impl::next(); } static constexpr T min() { return LIMMIN; } static constexpr T max() { return LIMMAX; } T operator()() { return next(); } private: static constexpr T rotl(const T x, int k) { return (x << k) | (x >> (64 - k)); } T next() { const T ans = rotl(s[1] * 5, 7) * 9; const T t = s[1] << 17; s[2] ^= s[0]; s[3] ^= s[1]; s[1] ^= s[2]; s[0] ^= s[3]; s[2] ^= t; s[3] = rotl(s[3], 45); return ans; } T s[4]; }; template class RNG { public: using result_type = typename Rng::result_type; using T = result_type; static constexpr T min() { return Rng::min(); } static constexpr T max() { return Rng::max(); } RNG() : RNG(std::random_device{}()) {} RNG(T seed) : m_rng(seed) {} T operator()() { return m_rng(); } template T val(T min, T max) { return std::uniform_int_distribution(min, max)(m_rng); } template Pair pair(T min, T max) { return std::minmax({val(min, max), val(min, max)}); } template Vec vec(int n, T min, T max) { return genVec(n, [&]() { return val(min, max); }); } template Vec> vvec(int n, int m, T min, T max) { return genVec>(n, [&]() { return vec(m, min, max); }); } private: Rng m_rng; }; RNG rng; RNG rng64; RNG rng_xo; RNG rng_xo64; class Scanner { public: Scanner(Istream& is = std::cin) : m_is{is} { m_is.tie(nullptr)->sync_with_stdio(false); } template T val() { T v; return m_is >> v, v; } template T val(T offset) { return val() - offset; } template Vec vec(int n) { return genVec(n, [&]() { return val(); }); } template Vec vec(int n, T offset) { return genVec(n, [&]() { return val(offset); }); } template Vec> vvec(int n, int m) { return genVec>(n, [&]() { return vec(m); }); } template Vec> vvec(int n, int m, const T offset) { return genVec>(n, [&]() { return vec(m, offset); }); } template auto tup() { return Tup{val()...}; } template auto tup(const Args&... offsets) { return Tup{val(offsets)...}; } private: Istream& m_is; }; Scanner in; class Printer { public: Printer(Ostream& os = std::cout) : m_os{os} { m_os << std::fixed << std::setprecision(15); } template int operator()(const Args&... args) { dump(args...); return 0; } template int ln(const Args&... args) { dump(args...), m_os << '\n'; return 0; } template int el(const Args&... args) { dump(args...), m_os << std::endl; return 0; } private: template void dump(const T& v) { m_os << v; } template void dump(const Vec& vs) { for (const int i : rep(vs.size())) { m_os << (i ? " " : ""), dump(vs[i]); } } template void dump(const Vec>& vss) { for (const int i : rep(vss.size())) { m_os << (i ? "\n" : ""), dump(vss[i]); } } template int dump(const T& v, const Ts&... args) { dump(v), m_os << ' ', dump(args...); return 0; } Ostream& m_os; }; Printer out; template auto ndVec(int const (&szs)[n], const T x = T{}) { if constexpr (i == n) { return x; } else { return std::vector(szs[i], ndVec(szs, x)); } } template T binSearch(T ng, T ok, F check) { while (std::abs(ok - ng) > 1) { const T mid = (ok + ng) / 2; (check(mid) ? ok : ng) = mid; } return ok; } template class modint { template static U modRef() { static u32 s_mod = 0; return s_mod; } template static U rootRef() { static u32 s_root = 0; return s_root; } template static U max2pRef() { static u32 s_max2p = 0; return s_max2p; } public: template static constexpr std::enable_if_t mod() { return mod_; } template static std::enable_if_t mod() { return modRef(); } template static constexpr std::enable_if_t root() { return root_; } template static std::enable_if_t root() { return rootRef(); } template static constexpr std::enable_if_t max2p() { return max2p_; } template static std::enable_if_t max2p() { return max2pRef(); } template static void setMod(std::enable_if_t m) { modRef() = m; } template static void setRoot(std::enable_if_t r) { rootRef() = r; } template static void setMax2p(std::enable_if_t m) { max2pRef() = m; } constexpr modint() : m_val{0} {} constexpr modint(i64 v) : m_val{normll(v)} {} constexpr void setRaw(u32 v) { m_val = v; } constexpr modint operator-() const { return modint{0} - (*this); } constexpr modint& operator+=(const modint& m) { m_val = norm(m_val + m.val()); return *this; } constexpr modint& operator-=(const modint& m) { m_val = norm(m_val + mod() - m.val()); return *this; } constexpr modint& operator*=(const modint& m) { m_val = normll((i64)m_val * (i64)m.val() % (i64)mod()); return *this; } constexpr modint& operator/=(const modint& m) { return *this *= m.inv(); } constexpr modint operator+(const modint& m) const { auto v = *this; return v += m; } constexpr modint operator-(const modint& m) const { auto v = *this; return v -= m; } constexpr modint operator*(const modint& m) const { auto v = *this; return v *= m; } constexpr modint operator/(const modint& m) const { auto v = *this; return v /= m; } constexpr bool operator==(const modint& m) const { return m_val == m.val(); } constexpr bool operator!=(const modint& m) const { return not(*this == m); } friend Istream& operator>>(Istream& is, modint& m) { i64 v; return is >> v, m = v, is; } friend Ostream& operator<<(Ostream& os, const modint& m) { return os << m.val(); } constexpr u32 val() const { return m_val; } template constexpr modint pow(I n) const { return power(*this, n); } constexpr modint inv() const { return pow(mod() - 2); } static modint sinv(u32 n) { static Vec is{1, 1}; for (u32 i = (u32)is.size(); i <= n; i++) { is.push_back(-is[mod() % i] * (mod() / i)); } return is[n]; } static modint fact(u32 n) { static Vec fs{1, 1}; for (u32 i = (u32)fs.size(); i <= n; i++) { fs.push_back(fs.back() * i); } return fs[n]; } static modint ifact(u32 n) { static Vec ifs{1, 1}; for (u32 i = (u32)ifs.size(); i <= n; i++) { ifs.push_back(ifs.back() * sinv(i)); } return ifs[n]; } static modint comb(int n, int k) { return k > n or k < 0 ? modint{0} : fact(n) * ifact(n - k) * ifact(k); } private: static constexpr u32 norm(u32 x) { return x < mod() ? x : x - mod(); } static constexpr u32 normll(i64 x) { return norm(u32(x % (i64)mod() + (i64)mod())); } u32 m_val; }; using modint_1000000007 = modint<1000000007, 5, 1>; using modint_998244353 = modint<998244353, 3, 23>; template using modint_dynamic = modint<0, 0, id>; template class Graph { struct Edge { Edge() = default; Edge(int i, int t, T c) : id{i}, to{t}, cost{c} {} int id; int to; T cost; operator int() const { return to; } }; public: Graph(int n) : m_v{n}, m_edges(n) {} void addEdge(int u, int v, bool bi = false) { assert(0 <= u and u < m_v); assert(0 <= v and v < m_v); m_edges[u].emplace_back(m_e, v, 1); if (bi) { m_edges[v].emplace_back(m_e, u, 1); } m_e++; } void addEdge(int u, int v, const T& c, bool bi = false) { assert(0 <= u and u < m_v); assert(0 <= v and v < m_v); m_edges[u].emplace_back(m_e, v, c); if (bi) { m_edges[v].emplace_back(m_e, u, c); } m_e++; } const Vec& operator[](const int u) const { assert(0 <= u and u < m_v); return m_edges[u]; } Vec& operator[](const int u) { assert(0 <= u and u < m_v); return m_edges[u]; } int v() const { return m_v; } int e() const { return m_e; } friend Ostream& operator<<(Ostream& os, const Graph& g) { for (int u : rep(g.v())) { for (const auto& [id, v, c] : g[u]) { os << "[" << id << "]: "; os << u << "->" << v << "(" << c << ")\n"; } } return os; } Vec sizes(int root = 0) const { const int N = v(); assert(0 <= root and root < N); Vec ss(N, 1); Fix([&](auto dfs, int u, int p) -> void { for (const auto& [id, v, c] : m_edges[u]) { static_cast(id); if (v == p) { continue; } dfs(v, u); ss[u] += ss[v]; } })(root, -1); return ss; } Vec depths(int root = 0) const { const int N = v(); assert(0 <= root and root < N); Vec ds(N, 0); Fix([&](auto dfs, int u, int p) -> void { for (const auto& [id, v, c] : m_edges[u]) { static_cast(id); if (v == p) { continue; } ds[v] = ds[u] + c; dfs(v, u); } })(root, -1); return ds; } Vec parents(int root = 0) const { const int N = v(); assert(0 <= root and root < N); Vec ps(N, -1); Fix([&](auto dfs, int u, int p) -> void { for (const auto& [id, v, c] : m_edges[u]) { static_cast(id); if (v == p) { continue; } ps[v] = u; dfs(v, u); } })(root, -1); return ps; } private: int m_v; int m_e = 0; Vec> m_edges; }; template class DualSeg { using F = typename OpMonoid::F; static constexpr F id() { return OpMonoid::id(); } public: DualSeg(const Vec& vs) : m_size(vs.size()), m_depth(clog(m_size) + 1), m_half(1 << m_depth), m_ops(m_half << 1, id()) { std::copy(vs.begin(), vs.end(), m_ops.begin() + m_half); } F get(int i) const { assert(0 <= i and i < m_size); F ans = id(); i += m_half; for (int h : per(m_depth)) { ans = compose(ans, m_ops[i >> h]); } return ans; } void set(int i, const F& f) { assert(0 <= i and i < m_size); i += m_half; clean(i), clean(i + 1); m_ops[i] = f; } void act(int l, int r, const F& f) { assert(0 <= l and r <= m_size); if (l >= r) { return; } int li = l + m_half, ri = r + m_half; clean(li), clean(ri); for (; li < ri; li >>= 1, ri >>= 1) { if (li & 1) { update(li++, f); } if (ri & 1) { update(--ri, f); } } } friend Ostream& operator<<(Ostream& os, const DualSeg& seg) { os << "["; for (int i : rep(seg.m_size)) { os << (i == 0 ? "" : ",") << seg.get(i); } return (os << "]\n"); } private: void down(int i) { update(i << 1, m_ops[i]), update(i << 1 | 1, m_ops[i]); m_ops[i] = id(); } void clean(int i) { const int b = (i / (i & -i)) >> 1; for (const int h : per(m_depth)) { const int v = i >> h; if (v > b) { break; } down(v); } } void update(int i, const F& f) { m_ops[i] = compose(f, m_ops[i]); } int m_size, m_depth, m_half; Vec m_ops; static inline OpMonoid compose; }; template class DSTable { using T = typename SemiGroup::T; public: DSTable(const Vec& vs) : m_size(vs.size()), m_depth(log2p1(m_size)), m_vss(m_depth, vs) { for (int d : rep(m_depth)) { const int w = 1 << (m_depth - d - 1); for (int i = 1; i * w < m_size; i += 2) { int l = i * w - 1, r = i * w; for (int j : irange(1, w)) { m_vss[d][l - j] = merge(vs[l - j], m_vss[d][l - j + 1]); if (r + j < m_size) { m_vss[d][r + j] = merge(vs[r + j], m_vss[d][r + j - 1]); } } } } } T fold(int l, int r) const { assert(0 <= l and l < r and r <= m_size); if (r - l == 1) { return m_vss.back()[l]; } const int d = m_depth - log2p1(l ^ (r - 1)); return merge(m_vss[d][l], m_vss[d][r - 1]); } private: int m_size, m_depth; Vec> m_vss; static inline SemiGroup merge; }; template class StaticRMQ { using T = typename TotalOrd::T; public: StaticRMQ(const Vec& vs) : m_size(vs.size()), m_bn(wind(m_size + bs - 1)), m_vals{vs}, m_bucket_vals([&]() { Vec ans(m_bn); for (int i : rep(m_size)) { ans[wind(i)] = (i % bs == 0 ? m_vals[i] : std::min(ans[wind(i)], m_vals[i], comp)); } return ans; }()), m_masks(m_size, 0), m_st(m_bucket_vals) { for (int i : rep(m_bn)) { Vec g(bs, m_size), stack; for (const int j : rep(bs)) { if (ind(i, j) >= m_size) { break; } for (; not stack.empty() and not comp(m_vals[stack.back()], m_vals[ind(i, j)]); stack.pop_back()) {} g[j] = stack.empty() ? m_size : stack.back(), stack.push_back(ind(i, j)); } for (int j : rep(bs)) { if (ind(i, j) >= m_size) { break; } m_masks[ind(i, j)] = g[j] == m_size ? static_cast(0) : (m_masks[g[j]] | static_cast(1) << (g[j] - i * bs)); } } } T fold(int l, int r) const { assert(0 <= l and l < r and r <= m_size); const int lb = (l + bs - 1) / bs, rb = r / bs; if (lb > rb) { return brmq(l, r); } else { return lb < rb ? (l < bs * lb ? (bs * rb < r ? std::min({m_st.fold(lb, rb), brmq(l, bs * lb), brmq(bs * rb, r)}, comp) : std::min(m_st.fold(lb, rb), brmq(l, bs * lb), comp)) : (bs * rb < r ? std::min( m_st.fold(lb, rb), brmq(bs * rb, r), comp) : m_st.fold(lb, rb))) : (l < bs * lb ? (bs * rb < r ? std::min( brmq(l, bs * lb), brmq(bs * rb, r), comp) : brmq(l, bs * lb)) : (bs * rb < r ? brmq(bs * rb, r) : T{})); } } private: using B = u64; static constexpr int bs = sizeof(B) * 8; static constexpr int bslog = log2p1(bs) - 1; static constexpr int wind(int n) { return n >> (bslog); } static constexpr int bind(int n) { return n ^ (wind(n) << bslog); } static constexpr int ind(int w, int b) { return (w << bslog) | b; } T brmq(int l, int r) const { const B w = m_masks[r - 1] >> (l % bs); return w == 0 ? m_vals[r - 1] : m_vals[l + lsbp1(w) - 1]; } struct SemiGroup { using T = typename TotalOrd::T; T operator()(const T& x1, const T& x2) const { return std::min(x1, x2, comp); } }; static inline TotalOrd comp; int m_size, m_bn; Vec m_vals, m_bucket_vals; Vec m_masks; DSTable m_st; }; #pragma endregion struct OpMonoid { using F = i64; static constexpr F id() { return INF; } F operator()(const F& f1, const F& f2) const { return (f1 == id() ? f2 : f1); } }; struct Ord { using T = i64; T operator()(const T& x1, const T& x2) const { return x1 < x2; } }; int main() { const auto [N, Q] = in.tup(); Vec ls(Q), rs(Q); Vec Bs(Q); for (int i : rep(Q)) { std::tie(ls[i], rs[i], Bs[i]) = in.tup(1, 0, 0); } auto is = iotaVec(Q); sortAll(is, [&](int i, int j) { return Bs[i] < Bs[j]; }); DualSeg seg(Vec(N, INF)); for (int i : is) { seg.act(ls[i], rs[i], Bs[i]); } Vec As(N); for (int i : rep(N)) { As[i] = seg.get(i); } StaticRMQ RMQ(As); for (int i : rep(Q)) { if (RMQ.fold(ls[i], rs[i]) != Bs[i]) { return out.ln(-1); } } out.ln(As); }