#include using namespace std; #define rep(i,n) for(ll i=0;i=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define pqueue(x) priority_queue,greater> #define all(x) (x).begin(),(x).end() #define CST(x) cout<> #define rev(x) reverse(x); using ll=long long; using vl=vector; using vvl=vector>; using pl=pair; using vpl=vector; using vvpl=vector; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[9]={0,1,-1,0,1,1,-1,-1,0}; const ll dx[9]={1,0,0,-1,1,-1,1,-1,0}; 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; } struct Intervals{ set st; Intervals(){ st.insert({-INF,-INF}); st.insert({INF,INF}); } void insert(pl p){//開区間pを挿入し、マージする auto x=st.lower_bound(p);x--; while(true){ auto q=*x; if((p.first<=q.first&&q.first<=p.second)||(q.first<=p.first&&p.first<=q.second)){ p.first=min(p.first,q.first); p.second=max(p.second,q.second); x=st.erase(x); } else if(q.second<=p.first)x++; else break; } st.insert(p); } pl get(ll i){//iを含む区間を返す もしそのような区間がなければ、{-INF,INF}を返す auto x=st.upper_bound({i,INF});x--; if(x->first<=i&&isecond)return *x; else return make_pair(-INF,INF); } bool same(ll l,ll r){//lとrが同じ区間に属しているか if(get(l).first==-INF)return false; else return get(l)==get(r); } void split(pl p){//区間pをちょうど取り除く 該当する区間がない場合は何も起こらない [x,x)を入力すると、そこで区間を分割するが、幅0の区間は捨てられる。 auto x=st.lower_bound(p);x--; vpl cand; while(true){ auto q=*x; if((p.first<=q.first&&q.first<=p.second)||(q.first<=p.first&&p.first<=q.second)){ if(q.first<=p.first){ if(q.first!=p.first)cand.push_back({q.first,p.first}); } if(p.second<=q.second){ if(p.second!=q.second)cand.push_back({p.second,q.second}); } x=st.erase(x); } else if(q.second> d >> q; Intervals iv; ll ans=0; while(q--){ ll l,r;cin >> l >> r; iv.insert({l,r+1}); auto p=iv.get(l); chmax(ans,p.second-p.first); cout << ans <