#include //#include //#include //#include #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a; i >-1; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a; i > b; --i) #define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define popcount __builtin_popcount #define popcountll __builtin_popcountll #define fi first #define se second using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll mod_998244353 = 998244353; constexpr ll INF = 1LL << 60; // #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") //using lll=boost::multiprecision::cpp_int; //using Double=boost::multiprecision::number>;//仮数部が1024桁 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; } ll mypow(ll x, ll n, const ll &p = -1) { //x^nをmodで割った余り if (p != -1) { x =(x%p+p)%p; } ll ret = 1; while (n > 0) { if (n & 1) { if (p != -1) ret = (ret * x) % p; else ret *= x; } if (p != -1) x = (x * x) % p; else x *= x; n >>= 1; } return ret; } using namespace std; //using namespace atcoder; template//S:the type of intervals,T:the type of data struct IntervalMerge{ struct interval{ S l,r; T content; interval(const S &_l,const S &_r,const T &_content):l(_l),r(_r),content(_content){} interval(){} constexpr bool operator<(const interval &rhs)const{ if(l!=rhs.l)return l<(rhs.l); return r<(rhs.r); } }; setst; IntervalMerge(){} IntervalMerge(vector &a){ int n=a.size(); a.eb(-1); int pos=0; while(pos void query(S l,S r,const T &x){//[l,r) auto itr=st.lower_bound(interval{l,l,numeric_limits::max()}); if(itr!=st.begin()){ auto pre_itr=prev(itr); auto pre_interval=*pre_itr; if(pre_itr->r>=l){ del(pre_itr->l,pre_itr->r,pre_itr->content); st.erase(pre_itr); if(pre_interval.content==x){ l=pre_interval.l; r=max(r,pre_interval.r); } else { add(pre_interval.l,l,pre_interval.content); st.emplace(pre_interval.l,l,pre_interval.content); if(rl)break; if(itr->r<=r){ del(itr->l,itr->r,itr->content); itr=st.erase(itr); }else{ interval cur=*itr; del(itr->l,itr->r,itr->content); itr=st.erase(itr); if(cur.content==x)r=cur.r; else{ add(r,cur.r,cur.content); st.emplace(r,cur.r,cur.content); } break; } } add(l,r,x); st.emplace(l,r,x); } }; using S=ll; using T=ll; mapmp; ll ans; void add(S l,S r,T x){ mp[r-l]++; chmax(ans,r-l); } void del(S l,S r,T x){ mp[r-l]--; if(mp[r-l]==0){ mp.erase(r-l); if(!mp.empty())ans=prev(mp.end())->first; } } void solve() { ll d,q; cin>>d>>q; IntervalMergeim; ans=0; while(q--){ ll a,b; cin>>a>>b; b++; im.query(a,b,1); cout<