#line 1 "a.cpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* macro */ #define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++) #define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--) #define Rep(i, a, n) for (i64 i = (i64)(a); i< (i64)(n); i++) #define RRep(i, a, n) for (i64 i = ((i64)(n-i64(1))); i>=(i64)(a); i--) #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define Bit(n) (1LL<<(n)) /* macro end */ /* template */ namespace ebi { #ifdef LOCAL #define debug(...) \ std::cerr << "LINE: " << __LINE__ << " [" << #__VA_ARGS__ << "]:", \ debug_out(__VA_ARGS__) #else #define debug(...) #endif void debug_out() { std::cerr << std::endl; } template void debug_out(Head h, Tail... t) { std::cerr << " " << h; if (sizeof...(t) > 0) std::cout << " :"; debug_out(t...); } template std::ostream& operator<<(std::ostream& os, std::pair pa) { return os << pa.first << " " << pa.second; } template std::ostream& operator<<(std::ostream& os, std::vector vec) { for (std::size_t i = 0; i < vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os; } using size_t = std::size_t; using i64 = std::int64_t; using u64 = std::uint64_t; using ld = long double; template void fill(std::vector &v) { for(T &e: v) std::cin >> e; } template inline bool chmin(T &a, T b) { if (a > b){ a = b; return true; } return false; } template inline bool chmax(T &a, T b) { if (a < b){ a = b; return true; } return false; } template T gcd(T a, T b){ if( b==0 ) return a; else return gcd(b, a%b); } template T lcm(T a, T b) { a /= gcd(a, b); return a*b; } template T Pow(T x, i64 n) { T res = 1; while(n>0){ if(n&1) res = res *x; x = x*x; n>>=1; } return res; } template T scan() { T val; std::cin >> val; return val; } constexpr i64 LNF = std::numeric_limits::max()/4; constexpr int INF = std::numeric_limits::max()/2; const std::vector dy = {1,0,-1,0,1,1,-1,-1}; const std::vector dx = {0,1,0,-1,1,-1,1,-1}; } /* template end */ #line 2 "data_structure/section_set.hpp" #line 6 "data_structure/section_set.hpp" namespace ebi { template struct section_set { private: std::set> set; public: section_set() { set.insert({std::numeric_limits::min(), std::numeric_limits::min()}); set.insert({std::numeric_limits::max(), std::numeric_limits::max()}); } // [l, r)を追加 void insert(T l, T r) { auto itr = std::prev(set.lower_bound({l, std::numeric_limits::min()})); if(l <= itr->second) { assert(itr->first <= l); l = itr->first; r = std::max(r, itr->second); set.erase(itr); } itr = set.lower_bound({l, -1}); while(itr->first <= r) { assert(l <= itr->first); r = std::max(r, itr->second); itr = set.erase(itr); } set.insert({l, r}); return; } // 集合内の[l, r)に含まれている要素を削除 void erase(T l, T r) { auto itr = std::prev(set.lower_bound({l, std::numeric_limits::min()})); if(l < itr->second) { assert(itr->first < l); set.insert({itr->first ,l}); if(r < itr->second) { set.insert({r, itr->second}); } set.erase(itr); } itr = set.lower_bound({l, std::numeric_limits::min()}); while(itr->first < r) { if(itr->second <= r) { itr = set.erase(itr); } else { set.insert({r, itr->second}); set.erase(itr); break; } } return; } bool find(T x) const { auto itr = std::prev(set.upper_bound({x, std::numeric_limits::max()})); if(x < itr->second) { assert(itr->first <= x); return true; } else { return false; } } bool find(T l, T r) const { auto itr = std::prev(set.upper_bound({l, std::numeric_limits::max()})); if(r <= itr->second) { assert(itr->first <= l); return true; } else { return false; } } std::pair belong(T x) const { auto itr = std::prev(set.upper_bound({x, std::numeric_limits::max()})); if(x <= itr->second) { assert(itr->first <= x); return *itr; } else { return {0, 0}; } } std::pair lower_bound(T l) const { return *set.lower_bound({l, -1}); } }; } #line 136 "a.cpp" namespace ebi { void main_() { i64 d; int q; std::cin >> d >> q; section_set set; i64 ans = 0; while(q--) { i64 a,b; std::cin >> a >> b; b++; set.insert(a, b); auto [l, r] = set.belong(a); chmax(ans, r-l); std::cout << ans << '\n'; } } } int main() { std::cout << std::fixed << std::setprecision(15); std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int t = 1; // std::cin >> t; while(t--) { ebi::main_(); } return 0; }