#define _USE_MATH_DEFINES #pragma region include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //// //#include // #pragma endregion //#include ///////// #pragma region typedef typedef long long LL; typedef long double LD; typedef unsigned long long ULL; #pragma endregion //typedef ////定数 const int INF = (int)1e9; const LL MOD = (LL)1e9+7; const LL LINF = (LL)4e18+20; const LD PI = acos(-1.0); const double EPS = 1e-9; ///////// using namespace::std; void solve(){ LL D,Q; cin>>D>>Q; vector > seq; vector dat(2); dat[0] = 0; dat[1] = D-1; seq.push_back( dat ); vector sya(2); while(Q--){ cin>>sya[0]>>sya[1]; int size = seq.size(); vector >next; LL ans = 0; for(int i=0;i temp(2); temp[0] = dat[0]; temp[1] = sya[0]-1; next.push_back( temp ); temp[0] = sya[1]+1; temp[1] = dat[1]; next.push_back( temp ); }else if(dat[0] <= sya[1] ){ vector temp(2); temp[0] = sya[1]+1; temp[1] = dat[1]; next.push_back( temp ); }else if(sya[0]<=dat[1] ){ vector temp(2); temp[0] = dat[0]; temp[1] = sya[0]-1; next.push_back( temp ); } } seq = next; size = seq.size(); ans = 0; if(size==0){ ans = D; } for(int i=0;i= 0 ){//一個前がある LL res = seq[i][0]-seq[i-1][1]-1; ans = max(ans,res); }else{ LL res = seq[i][0]-0; ans = max(ans,res); } if(i+1 < size ){//一個次がある。 LL res = seq[i+1][0]-seq[i][1]-1; ans = max(ans,res); }else{ LL res = D-1 - seq[i][1]; ans = max(ans,res); } } cout << ans << endl; } } #pragma region main signed main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed;//小数を10進数表示 cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別 solve(); } #pragma endregion //main()