//#pragma GCC target("avx") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #pragma region header using namespace std; using lint = long long; const int dx[] = { 1, 0, -1, 0 }; const int dy[] = { 0, 1, 0, -1 }; const long long INF = 1ll << 60; const int mod = 1000000007; #define prique(T) priority_queue, greater> #define init std::ios::sync_with_stdio(false);std::cin.tie(0); template inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return true; } return false; } #pragma endregion class SegmentMap : public std::map { private: bool flagToMergeAdjacentSegment; public: // if merge [l, c] and [c+1, r], set flagToMergeAdjacentSegment to true SegmentMap(bool flagToMergeAdjacentSegment) : flagToMergeAdjacentSegment(flagToMergeAdjacentSegment) { } // __exist -> iterator pair(l, r) (contain p) // noexist -> map.end() auto get(signed p) const { auto it = upper_bound(p); if (it == begin() || (--it)->second < p) return end(); return it; } // insert segment [l, r] void insert(signed l, signed r) { auto itl = upper_bound(l), itr = upper_bound(r + flagToMergeAdjacentSegment); if (itl != begin()) { if ((--itl)->second < l - flagToMergeAdjacentSegment) ++itl; } if (itl != itr) { l = std::min(l, itl->first); r = std::max(r, std::prev(itr)->second); erase(itl, itr); } (*this)[l] = r; } // remove segment [l, r] void remove(signed l, signed r) { auto itl = upper_bound(l), itr = upper_bound(r); if (itl != begin()) { if ((--itl)->second < l) ++itl; } if (itl == itr) return; int tl = std::min(l, itl->first), tr = std::max(r, std::prev(itr)->second); erase(itl, itr); if (tl < l) (*this)[tl] = l - 1; if (r < tr) (*this)[r + 1] = tr; } // Is p and q in same segment? bool same(signed p, signed q) const { const auto&& it = get(p); return it != end() && it->first <= q && q <= it->second; } }; int main(void) { init; lint d, q; cin >> d >> q; SegmentMap s(true); lint dynamicans = 0; for (int _ = 0; _ < q; ++_) { lint a, b; cin >> a >> b; s.insert(a, b); auto itr = s.get(a); chmax(dynamicans, itr->second - itr->first + 1); cout << dynamicans << endl; } return 0; }