#include using namespace std; #define ALL(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const pair&p){ os< ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os<>d>>q; using P=pair; set

st; st.insert(P(-LINF,-LINF)); st.insert(P(LINF,LINF)); ll ans=0; rep(_,q){ ll a,b;cin>>a>>b;b++; auto ite=st.lower_bound(P(a,b)); ite=prev(ite); if((ite->first)<=a and b<=(ite->second)){ cout<second)>=a){ a=ite->first; ite=st.erase(ite); }else ite=next(ite); while(b>=(ite->second))ite=st.erase(ite); if(bfirst){ } else{ b=ite->second; st.erase(ite); } chmax(ans,b-a); st.insert(P(a,b)); cout<