//////////////////////////////////////// /// tu3 pro-con template /// //////////////////////////////////////// #include "bits/stdc++.h" using namespace std; // -- typedefs -- // #define EPS 1e-9 typedef long long llong; // -- loop macros -- // #define LOOP_TYPE(s,n) std::remove_reference_t> #define FOR(i,s,n) for (auto i = LOOP_TYPE(s,n)(s); i < LOOP_TYPE(s,n)(n); i++) #define FORR(i,s,n) for (auto i = LOOP_TYPE(s,n)(n)-1; i != LOOP_TYPE(s,n)(s)-1; i--) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) FORR(i,0,n) #define FORE(exp) for (auto && exp) #define allof(c) c.begin(), c.end() #define partof(c,s,e) c.begin() + (s), c.begin() + (e) // -- functors -- // #define PREDICATE(t,a,...) [&](const t & a) -> bool { return __VA_ARGS__; } #define PRED(a,...) PREDICATE(auto,a,__VA_ARGS__) #define COMPARISON(t,a,b,...) [&](const t & a, const t & b) -> bool { return __VA_ARGS__; } #define COMP(a,b,...) COMPARISON(auto,a,b,__VA_ARGS__) #define CONV1(a,...) [&](const auto & a) -> auto { return __VA_ARGS__; } #define CONV2(a,b,...) [&](const auto & a, const auto & b) -> auto { return __VA_ARGS__; } #define CONV3(a,b,c,...) [&](const auto & a, const auto & b, const auto & c) -> auto { return __VA_ARGS__; } #define TIE(...) auto tie() const { return std::tie(__VA_ARGS__); } #define LESS(t) bool operator <(const t &rhs) const { return tie() < rhs.tie(); } #define GREATER(t) bool operator >(const t &rhs) const { return tie() > rhs.tie(); } // -- I/O Helper -- // struct _Reader { istream& cin; template _Reader operator ,(T& rhs) { cin >> rhs; return *this; } }; struct _Writer { ostream& cout; const char* d{ " " }; bool f{}; template _Writer operator ,(const T& rhs) { cout << (f ? d : "") << rhs; f = 1; return *this; } }; #define READ(t,...) t __VA_ARGS__; (_Reader{cin}), __VA_ARGS__ #define WRITE(...) do { (_Writer{cout}), __VA_ARGS__; cout << endl; } while (false) #define WRITELN(...) do { (_Writer{cout, "\n"}), __VA_ARGS__; cout << endl; } while (false) #define WRITE2D(vevector) FORE(row : vevector) WRITE(row) #ifdef _DEBUG #define DEBUG(...) (_Writer{cerr}), "DEBUG -> ", __VA_ARGS__, "\n" #else #define DEBUG(...) #endif // -- vevector -- // template struct vevector : vector> { vevector(size_t n = 0, size_t m = 0, const T& initial = T()) : vector>(n, vector(m, initial)) { } }; template struct vevevector : vector> { vevevector(size_t n = 0, size_t m = 0, size_t l = 0, const T& initial = T()) : vector>(n, vevector(m, l, initial)) { } }; template struct vevevevector : vector> { vevevevector(size_t n = 0, size_t m = 0, size_t l = 0, size_t k = 0, const T& initial = T()) : vector>(n, vevevector(m, l, k, initial)) { } }; namespace std { template istream& operator >> (istream& in, pair& p) { in >> p.first >> p.second; return in; } template ostream& operator << (ostream& out, const pair& p) { out << p.first << " " << p.second; return out; } } template T read() { T t; cin >> t; return t; } template vector read(int n) { vector v; REP(i, n) { v.push_back(read()); } return v; } template vevector read(int n, int m) { vevector v; REP(i, n) v.push_back(read(m)); return v; } template vector readjag() { return read(read()); } template vevector readjag(int n) { vevector v; REP(i, n) v.push_back(readjag()); return v; } template struct iter_range_t { T beg, end; }; template iter_range_t iter_range(T beg, T end) { return iter_range_t{beg, end}; } template ostream& operator << (ostream& out, iter_range_t v) { if (v.beg != v.end) { out << *v.beg++; while (v.beg != v.end) { out << " " << *v.beg++; } } return out; } template ostream& operator << (ostream& out, const vector& v) { return out << iter_range(allof(v)); } // -- etc -- // template T infinity_value(); template <> int infinity_value() { return int(1) << 30; } template <> llong infinity_value() { return llong(1) << 60; } template <> double infinity_value() { return 1e+300 * 1e+300; } #define INF(T) infinity_value() inline int sign_of(double x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); } template bool in_range(TInt val, TInt min, TInt max) { return val >= min && val < max; } template <> bool in_range(double val, double min, double max) { return val - min > -EPS && val - max < EPS; } template bool in_range2d(TInt x, TInt y, TInt w, TInt h) { return x >= 0 && x < w && y >= 0 && y < h; } vector iotavn(int start, int count) { vector r(count); iota(allof(r), start); return r; } //// start up //// void solve(); int32_t main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed; cout << setprecision(std::numeric_limits::max_digits10); solve(); return 0; } //////////////////// //// template end //////////////////// struct RangeMerge : std::map { pair find(llong l, llong r, bool merge) { auto lit = lower_bound(l); if (lit != begin()) { auto llit = lit; if (!merge ? l < (--llit)->second : l <= (--llit)->second) { lit = llit; } } auto rit = lower_bound(r); if (rit != end()) { if (merge && rit->first == r) { ++rit; } } return { lit, rit }; } void add(llong l, llong r, bool merge = false) { auto p = find(l, r, merge); auto lit = p.first; auto rit = p.second; if (lit != end()) { l = min(l, lit->first); } if (rit != begin()) { auto rr = rit; r = max(r, (--rr)->second); } erase(lit, rit); if (l != r) { insert({ l, r }); maxs = max(maxs, r - l); } } llong maxs{}; bool test(llong x) { auto p = find(x, x, false); auto lit = p.first; return lit != end() && x >= lit->first && x < lit->second; } }; void solve() { READ(llong, D, Q); RangeMerge m; REP(i, Q) { READ(llong, a, b); m.add(a, b + 1, true); WRITE(m.maxs); } }