結果

問題 No.2974 関数の芽
ユーザー 👑 p-adicp-adic
提出日時 2023-11-15 09:35:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 321 ms / 2,000 ms
コード長 17,834 bytes
コンパイル時間 3,711 ms
コンパイル使用メモリ 239,168 KB
実行使用メモリ 26,912 KB
最終ジャッジ日時 2024-09-22 19:29:21
合計ジャッジ時間 7,986 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
15,872 KB
testcase_01 AC 11 ms
16,000 KB
testcase_02 AC 11 ms
15,872 KB
testcase_03 AC 11 ms
15,872 KB
testcase_04 AC 11 ms
16,000 KB
testcase_05 AC 11 ms
16,000 KB
testcase_06 AC 11 ms
16,000 KB
testcase_07 AC 11 ms
15,872 KB
testcase_08 AC 11 ms
16,000 KB
testcase_09 AC 11 ms
15,872 KB
testcase_10 AC 11 ms
15,872 KB
testcase_11 AC 11 ms
16,000 KB
testcase_12 AC 12 ms
16,000 KB
testcase_13 AC 26 ms
16,384 KB
testcase_14 AC 163 ms
19,840 KB
testcase_15 AC 292 ms
26,880 KB
testcase_16 AC 173 ms
26,752 KB
testcase_17 AC 286 ms
26,880 KB
testcase_18 AC 265 ms
26,752 KB
testcase_19 AC 272 ms
26,880 KB
testcase_20 AC 265 ms
26,752 KB
testcase_21 AC 271 ms
26,752 KB
testcase_22 AC 286 ms
26,880 KB
testcase_23 AC 321 ms
26,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 一次関数の代わりに割り算を用いた比較
// 何故か実行のたびに実行時間がものすごく変わる(228〜345[ms])
#ifdef DEBUG
  #define _GLIBCXX_DEBUG
  #define REPEAT_MAIN( BOUND ) START_MAIN; signal( SIGABRT , &AlertAbort ); AutoCheck( exec_mode ); if( exec_mode == debug_mode || exec_mode == library_search_mode ){ return 0; } else if( exec_mode == experiment_mode ){ Experiment(); return 0; } else if( exec_mode == small_test_mode ){ SmallTest(); return 0; }; DEXPR( int , bound_test_case_num , BOUND , min( BOUND , 100 ) ); int test_case_num = 1; if( exec_mode == solve_mode ){ if constexpr( bound_test_case_num > 1 ){ SET_ASSERT( test_case_num , 1 , bound_test_case_num ); } } else if( exec_mode == random_test_mode ){ CERR( "ランダムテストを行う回数を指定してください。" ); cin >> test_case_num; } FINISH_MAIN
  #define DEXPR( LL , BOUND , VALUE , DEBUG_VALUE ) CEXPR( LL , BOUND , DEBUG_VALUE )
  #define ASSERT( A , MIN , MAX ) CERR( "ASSERTチェック: " , ( MIN ) , ( ( MIN ) <= A ? "<=" : ">" ) , A , ( A <= ( MAX ) ? "<=" : ">" ) , ( MAX ) ); assert( ( MIN ) <= A && A <= ( MAX ) )
  #define SET_ASSERT( A , MIN , MAX ) if( exec_mode == solve_mode ){ cin >> A; ASSERT( A , MIN , MAX ); } else if( exec_mode == random_test_mode ){ CERR( #A , " = " , ( A = GetRand( MIN , MAX ) ) ); } else { assert( false ); }
  #define SOLVE_ONLY static_assert( __FUNCTION__[0] == 'S' )
  #define CERR( ... ) VariadicCout( cerr , __VA_ARGS__ ) << endl
  #define COUT( ... ) VariadicCout( cout << "出力: " , __VA_ARGS__ ) << endl
  #define CERR_A( A , N ) OUTPUT_ARRAY( cerr , A , N ) << endl
  #define COUT_A( A , N ) cout << "出力: "; OUTPUT_ARRAY( cout , A , N ) << endl
  #define CERR_ITR( A ) OUTPUT_ITR( cerr , A ) << endl
  #define COUT_ITR( A ) cout << "出力: "; OUTPUT_ITR( cout , A ) << endl
#else
  #pragma GCC optimize ( "O3" )
  #pragma GCC optimize ( "unroll-loops" )
  #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" )
  #define REPEAT_MAIN( BOUND ) START_MAIN; CEXPR( int , bound_test_case_num , BOUND ); int test_case_num = 1; if constexpr( bound_test_case_num > 1 ){ SET_ASSERT( test_case_num , 1 , bound_test_case_num ); } FINISH_MAIN
  #define DEXPR( LL , BOUND , VALUE , DEBUG_VALUE ) CEXPR( LL , BOUND , VALUE )
  #define ASSERT( A , MIN , MAX ) assert( ( MIN ) <= A && A <= ( MAX ) )
  #define SET_ASSERT( A , MIN , MAX ) cin >> A; ASSERT( A , MIN , MAX )
  #define SOLVE_ONLY 
  #define CERR( ... ) 
  #define COUT( ... ) VariadicCout( cout , __VA_ARGS__ ) << "\n"
  #define CERR_A( A , N ) 
  #define COUT_A( A , N ) OUTPUT_ARRAY( cout , A , N ) << "\n"
  #define CERR_ITR( A ) 
  #define COUT_ITR( A ) OUTPUT_ITR( cout , A ) << "\n"
#endif
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#define START_MAIN int main(){ ios_base::sync_with_stdio( false ); cin.tie( nullptr )
#define FINISH_MAIN REPEAT( test_case_num ){ if constexpr( bound_test_case_num > 1 ){ CERR( "testcase " , VARIABLE_FOR_REPEAT_test_case_num , ":" ); } Solve(); CERR( "" ); } }
#define TYPE_OF( VAR ) decay_t<decltype( VAR )>
#define CEXPR( LL , BOUND , VALUE ) constexpr LL BOUND = VALUE
#define CIN( LL , ... ) SOLVE_ONLY; LL __VA_ARGS__; VariadicCin( cin , __VA_ARGS__ )
#define CIN_ASSERT( A , MIN , MAX ) TYPE_OF( MAX ) A; SET_ASSERT( A , MIN , MAX )
#define SET_A( A , N ) SOLVE_ONLY; FOR( VARIABLE_FOR_CIN_A , 0 , N ){ cin >> A[VARIABLE_FOR_CIN_A]; }
#define CIN_A( LL , A , N ) vector<LL> A( N ); SET_A( A , N );
#define GETLINE_SEPARATE( SEPARATOR , ... ) SOLVE_ONLY; string __VA_ARGS__; VariadicGetline( cin , SEPARATOR , __VA_ARGS__ )
#define GETLINE( ... ) SOLVE_ONLY; GETLINE_SEPARATE( '\n' , __VA_ARGS__ )
#define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ )
#define FOREQ( VAR , INITIAL , FINAL ) for( TYPE_OF( FINAL ) VAR = INITIAL ; VAR <= FINAL ; VAR ++ )
#define FOREQINV( VAR , INITIAL , FINAL ) for( TYPE_OF( INITIAL ) VAR = INITIAL ; VAR >= FINAL ; VAR -- )
#define AUTO_ITR( ARRAY ) auto itr_ ## ARRAY = ARRAY .begin() , end_ ## ARRAY = ARRAY .end()
#define FOR_ITR( ARRAY ) for( AUTO_ITR( ARRAY ) , itr = itr_ ## ARRAY ; itr_ ## ARRAY != end_ ## ARRAY ; itr_ ## ARRAY ++ , itr++ )
#define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT_ ## HOW_MANY_TIMES , 0 , HOW_MANY_TIMES )
#define SET_PRECISION( DECIMAL_DIGITS ) cout << fixed << setprecision( DECIMAL_DIGITS )
#define OUTPUT_ARRAY( OS , A , N ) FOR( VARIABLE_FOR_OUTPUT_ARRAY , 0 , N ){ OS << A[VARIABLE_FOR_OUTPUT_ARRAY] << (VARIABLE_FOR_OUTPUT_ARRAY==N-1?"":" "); } OS
#define OUTPUT_ITR( OS , A ) { auto ITERATOR_FOR_OUTPUT_ITR = A.begin() , END_FOR_OUTPUT_ITR = A.end(); bool VARIABLE_FOR_OUTPUT_ITR = ITERATOR_FOR_COUT_ITR != END_FOR_COUT_ITR; while( VARIABLE_FOR_OUTPUT_ITR ){ OS << *ITERATOR_FOR_COUT_ITR; ( VARIABLE_FOR_OUTPUT_ITR = ++ITERATOR_FOR_COUT_ITR != END_FOR_COUT_ITR ) ? OS : OS << " "; } } OS
#define RETURN( ... ) SOLVE_ONLY; COUT( __VA_ARGS__ ); return
#define COMPARE( ... ) auto naive = Naive( __VA_ARGS__ ); auto answer = Answer( __VA_ARGS__ ); bool match = naive == answer; COUT( #__VA_ARGS__ , ":" , naive , match ? "==" : "!=" , answer ); if( !match ){ return; }

// 入出力用
template <class Traits> inline basic_istream<char,Traits>& VariadicCin( basic_istream<char,Traits>& is ) { return is; }
template <class Traits , typename Arg , typename... ARGS> inline basic_istream<char,Traits>& VariadicCin( basic_istream<char,Traits>& is , Arg& arg , ARGS&... args ) { return VariadicCin( is >> arg , args... ); }
template <class Traits> inline basic_istream<char,Traits>& VariadicGetline( basic_istream<char,Traits>& is , const char& separator ) { return is; }
template <class Traits , typename Arg , typename... ARGS> inline basic_istream<char,Traits>& VariadicGetline( basic_istream<char,Traits>& is , const char& separator , Arg& arg , ARGS&... args ) { return VariadicGetline( getline( is , arg , separator ) , separator , args... ); }
template <class Traits , typename Arg> inline basic_ostream<char,Traits>& VariadicCout( basic_ostream<char,Traits>& os , const Arg& arg ) { return os << arg; }
template <class Traits , typename Arg1 , typename Arg2 , typename... ARGS> inline basic_ostream<char,Traits>& VariadicCout( basic_ostream<char,Traits>& os , const Arg1& arg1 , const Arg2& arg2 , const ARGS&... args ) { return VariadicCout( os << arg1 << " " , arg2 , args... ); }

// 算術用
template <typename T> constexpr T PositiveBaseResidue( const T& a , const T& p ){ return a >= 0 ? a % p : p - 1 - ( ( - ( a + 1 ) ) % p ); }
template <typename T> constexpr T Residue( const T& a , const T& p ){ return PositiveBaseResidue( a , p < 0 ? -p : p ); }
template <typename T> constexpr T PositiveBaseQuotient( const T& a , const T& p ){ return ( a - PositiveBaseResidue( a , p ) ) / p; }
template <typename T> constexpr T Quotient( const T& a , const T& p ){ return p < 0 ? PositiveBaseQuotient( -a , -p ) : PositiveBaseQuotient( a , p ); }

// 二分探索テンプレート
// EXPRESSIONがANSWERの広義単調関数の時、EXPRESSION >= TARGETの整数解を格納。
#define BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , DESIRED_INEQUALITY , TARGET , INEQUALITY_FOR_CHECK , UPDATE_U , UPDATE_L , UPDATE_ANSWER ) \
  static_assert( ! is_same<TYPE_OF( TARGET ),uint>::value && ! is_same<TYPE_OF( TARGET ),ull>::value ); \
  ll ANSWER = MINIMUM;							\
  ll VARIABLE_FOR_BINARY_SEARCH_L = MINIMUM;				\
  ll VARIABLE_FOR_BINARY_SEARCH_U = MAXIMUM;				\
  ANSWER = UPDATE_ANSWER;						\
  ll VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH;				\
  while( VARIABLE_FOR_BINARY_SEARCH_L < VARIABLE_FOR_BINARY_SEARCH_U ){ \
    VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = ( EXPRESSION ) - ( TARGET ); \
    CERR( "二分探索中:" , VARIABLE_FOR_BINARY_SEARCH_L , "<=" , ANSWER , "<=" , VARIABLE_FOR_BINARY_SEARCH_U , ":" , EXPRESSION , "-" , TARGET , "=" , VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH ); \
    if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH INEQUALITY_FOR_CHECK 0 ){ \
      VARIABLE_FOR_BINARY_SEARCH_U = UPDATE_U;				\
    } else {								\
      VARIABLE_FOR_BINARY_SEARCH_L = UPDATE_L;				\
    }									\
    ANSWER = UPDATE_ANSWER;						\
  }									\
  if( VARIABLE_FOR_BINARY_SEARCH_L > VARIABLE_FOR_BINARY_SEARCH_U ){	\
    CERR( "二分探索失敗:" , VARIABLE_FOR_BINARY_SEARCH_L , ">" , VARIABLE_FOR_BINARY_SEARCH_U ); \
    ANSWER = MAXIMUM + 1;						\
  } else {								\
    CERR( "二分探索終了:" , VARIABLE_FOR_BINARY_SEARCH_L , "<=" , ANSWER , "<=" , VARIABLE_FOR_BINARY_SEARCH_U , ":" , EXPRESSION , ( EXPRESSION > TARGET ? ">" : EXPRESSION < TARGET ? "<" : "=" ) , TARGET ); \
    if( EXPRESSION DESIRED_INEQUALITY TARGET ){				\
      CERR( "二分探索成功:" , #ANSWER , "=" , ANSWER );			\
    } else {								\
      CERR( "二分探索失敗:" , EXPRESSION , "<>"[EXPRESSION > TARGET],  TARGET ); \
      ANSWER = MAXIMUM + 1;						\
    }									\
  }									\

// 単調増加の時にEXPRESSION >= TARGETの最小解を格納。
#define BS1( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET )		\
  BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , >= , TARGET , >= , ANSWER , ANSWER + 1 , ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \

// 単調増加の時にEXPRESSION <= TARGETの最大解を格納。
#define BS2( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET )		\
  BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , <= , TARGET , > , ANSWER - 1 , ANSWER , ( VARIABLE_FOR_BINARY_SEARCH_L + 1 + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \

// 単調減少の時にEXPRESSION >= TARGETの最大解を格納。
#define BS3( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET )		\
  BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , >= , TARGET , < , ANSWER - 1 , ANSWER , ( VARIABLE_FOR_BINARY_SEARCH_L + 1 + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \

// 単調減少の時にEXPRESSION <= TARGETの最小解を格納。
#define BS4( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET )		\
  BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , <= , TARGET , <= , ANSWER , ANSWER + 1 , ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \

// デバッグ用
#ifdef DEBUG
  inline void AlertAbort( int n ) { CERR( "abort関数が呼ばれました。assertマクロのメッセージが出力されていない場合はオーバーフローの有無を確認をしてください。" ); }
  void AutoCheck( int& exec_mode );
  inline void Solve();
  inline void Experiment();
  inline void SmallTest();
  inline void RandomTest();
  ll GetRand( const ll& Rand_min , const ll& Rand_max );
  int exec_mode;
  CEXPR( int , solve_mode , 0 );
  CEXPR( int , debug_mode , 1 );
  CEXPR( int , library_search_mode , 2 );
  CEXPR( int , experiment_mode , 3 );
  CEXPR( int , small_test_mode , 4 );
  CEXPR( int , random_test_mode , 5 );
#endif

template <typename T , int N>
class BIT
{
private:
  T m_fenwick[N + 1];

public:
  inline BIT();
  BIT( const T ( & a )[N] );

  inline void Set( const int& i , const T& n );

  inline BIT<T,N>& operator+=( const T ( & a )[N] );
  void Add( const int& i , const T& n );

  T InitialSegmentSum( const int& i_final );
  inline T IntervalSum( const int& i_start , const int& i_final );
  
};

template <typename T , int N> inline BIT<T,N>::BIT() : m_fenwick() {}
template <typename T , int N>
BIT<T,N>::BIT( const T ( & a )[N] ) : m_fenwick()
{

  for( int j = 1 ; j <= N ; j++ ){

    T& fenwick_j = m_fenwick[j];
    int i = j - 1;
    fenwick_j = a[i];
    int i_lim = j - ( j & -j );

    while( i != i_lim ){

      fenwick_j += m_fenwick[i];
      i -= ( i & -i );

    }

  }

}

template <typename T , int N> inline void BIT<T,N>::Set( const int& i , const T& n ) { Add( i , n - IntervalSum( i , i ) ); }

template <typename T , int N> inline BIT<T,N>& BIT<T,N>::operator+=( const T ( & a )[N] ) { for( int i = 0 ; i < N ; i++ ){ Add( i , a[i] ); } return *this; }

template <typename T , int N>
void BIT<T,N>::Add( const int& i , const T& n )
{
  
  int j = i + 1;

  while( j <= N ){

    m_fenwick[j] += n;
    j += ( j & -j );

  }

  return;
  
}

template <typename T , int N> 
T BIT<T,N>::InitialSegmentSum( const int& i_final )
{

  T sum = 0;
  int j = ( i_final < N ? i_final : N - 1 ) + 1;

  while( j > 0 ){

    sum += m_fenwick[j];
    j -= j & -j;
    
  }

  return sum;
  
}

template <typename T , int N> inline T BIT<T,N>::IntervalSum( const int& i_start , const int& i_final ) { return InitialSegmentSum( i_final ) - InitialSegmentSum( i_start - 1 ); }

template <typename T , int N>
class IntervalAddBIT
{
private:
  // 母関数の微分の負の階差数列((i-1)a_{i-1} - ia_i)の管理
  BIT<T,N> m_bit_0;
  // 階差数列(a_i - a_{i-1})の管理
  BIT<T,N> m_bit_1;

public:
  inline IntervalAddBIT();
  inline IntervalAddBIT( const T ( & a )[N] );

  inline void Set( const int& i , const T& n );

  inline IntervalAddBIT<T,N>& operator+=( const T ( & a )[N] );
  inline void Add( const int& i , const T& n );
  inline void IntervalAdd( const int& i_start , const int& i_final , const T& n );

  inline T InitialSegmentSum( const int& i_final );
  inline T IntervalSum( const int& i_start , const int& i_final );
  
};

template <typename T , int N> inline IntervalAddBIT<T,N>::IntervalAddBIT() : m_bit_0() , m_bit_1() {}
template <typename T , int N> inline IntervalAddBIT<T,N>::IntervalAddBIT( const T ( & a )[N] ) : m_bit_0() , m_bit_1() { operator+=( a ); }

template <typename T , int N> inline void IntervalAddBIT<T,N>::Set( const int& i , const T& n ) { Add( i , n - IntervalSum( i , i ) ); }

template <typename T , int N> inline IntervalAddBIT<T,N>& IntervalAddBIT<T,N>::operator+=( const T ( & a )[N] ) { for( int i = 0 ; i < N ; i++ ){ Add( i , a[i] ); } return *this; }

template <typename T , int N> inline void IntervalAddBIT<T,N>::Add( const int& i , const T& n ) { IntervalAdd( i , i , n ); }

template <typename T , int N> inline void IntervalAddBIT<T,N>::IntervalAdd( const int& i_start , const int& i_final , const T& n ) { m_bit_0.Add( i_start , - ( i_start - 1 ) * n ); m_bit_0.Add( i_final + 1 , i_final * n ); m_bit_1.Add( i_start , n ); m_bit_1.Add( i_final + 1 , - n ); }


template <typename T , int N> inline T IntervalAddBIT<T,N>::InitialSegmentSum( const int& i_final ) { return m_bit_0.InitialSegmentSum( i_final ) + i_final * m_bit_1.InitialSegmentSum( i_final ); }

template <typename T , int N> inline T IntervalAddBIT<T,N>::IntervalSum( const int& i_start , const int& i_final ) { return InitialSegmentSum( i_final ) - InitialSegmentSum( i_start - 1 ); }


inline void Solve()
{
  DEXPR( int , bound_Q , 100000 , 100 );
  CIN_ASSERT( Q , 1 , bound_Q );
  CEXPR( ll , bound , 1000000000 );
  ll KM[bound_Q][2];
  ll LN[bound_Q][2];
  ll X[bound_Q];
  map<ll,int> X_inv{};
  X_inv[-bound-1];
  X_inv[bound+1];
  FOR( q , 0 , Q ){
    CIN_ASSERT( Kq , -bound , bound );
    CIN_ASSERT( Lq , -bound , bound );
    CIN_ASSERT( Mq , -bound , bound );
    CIN_ASSERT( Nq , -bound , bound );
    CIN_ASSERT( Xq , -bound , bound );
    ll ( &KMq )[2] = KM[q];
    ll ( &LNq )[2] = LN[q];
    KMq[0] = Kq;
    LNq[0] = Lq;
    KMq[1] = Mq;
    LNq[1] = Nq;
    X_inv[X[q] = Xq];
  }
  ll TheAtsuX[bound_Q+2];
  int i_max = -1;
  FOR_ITR( X_inv ){
    TheAtsuX[itr->second = ++i_max] = itr->first;
  }
  IntervalAddBIT<ll,bound_Q+2> FGL[2][2] = {};
  IntervalAddBIT<ll,bound_Q+2> FGR[2][2] = {};
  FOR( q , 0 , Q ){
    ll ( &KMq )[2] = KM[q];
    ll ( &LNq )[2] = LN[q];
    FOR( j , 0 , 2 ){
      ll& KMqj = KMq[j];
      ll& LNqj = LNq[j];
      IntervalAddBIT<ll,bound_Q+2> ( &FGLj )[2] = FGL[j];
      IntervalAddBIT<ll,bound_Q+2> ( &FGRj )[2] = FGR[j];
      if( KMqj == 0 ){
	if( LNqj > 0 ){
	  FGLj[0].IntervalAdd( 0 , i_max , LNqj );
	  FGRj[0].IntervalAdd( 0 , i_max , LNqj );
	}
      } else if( KMqj > 0 ){
	ll div = -Quotient( LNqj , KMqj );
	BS1( i , 0 , i_max , TheAtsuX[i] , div );
	if( LNqj % KMqj == 0 && TheAtsuX[i] == -LNqj / KMqj ){
	  FGLj[0].IntervalAdd( i + 1 , i_max , LNqj );
	  FGLj[1].IntervalAdd( i + 1 , i_max , KMqj );
	} else {
	  FGLj[0].IntervalAdd( i , i_max , LNqj );
	  FGLj[1].IntervalAdd( i , i_max , KMqj );
	}
	FGRj[0].IntervalAdd( i , i_max , LNqj );
	FGRj[1].IntervalAdd( i , i_max , KMqj );
      } else {
	ll div = Quotient( LNqj , -KMqj );
	BS2( i , 0 , i_max , TheAtsuX[i] , div );
	if( LNqj % KMqj == 0 && TheAtsuX[i] == - LNqj / KMqj ){
	  FGLj[0].IntervalAdd( 0 , i - 1 , LNqj );
	  FGLj[1].IntervalAdd( 0 , i - 1 , KMqj );
	} else {
	  FGLj[0].IntervalAdd( 0 , i , LNqj );
	  FGLj[1].IntervalAdd( 0 , i , KMqj );
	}
	FGRj[0].IntervalAdd( 0 , i , LNqj );
	FGRj[1].IntervalAdd( 0 , i , KMqj );
      }
    }
    IntervalAddBIT<ll,bound_Q+2> ( &FL )[2] = FGL[0];
    IntervalAddBIT<ll,bound_Q+2> ( &FR )[2] = FGR[0];
    IntervalAddBIT<ll,bound_Q+2> ( &GL )[2] = FGL[1];
    IntervalAddBIT<ll,bound_Q+2> ( &GR )[2] = FGR[1];
    int& i = X_inv[X[q]];
    if(
       FL[0].IntervalSum( i , i ) == GL[0].IntervalSum( i , i ) &&
       FL[1].IntervalSum( i , i ) == GL[1].IntervalSum( i , i ) &&
       FR[1].IntervalSum( i , i ) == GR[1].IntervalSum( i , i )
       ){
      COUT( "Yes" );
    } else {
      COUT( "No" );
    }
  }
}

inline void Experiment()
{
  // CEXPR( int , bound , 10 );
  // FOREQ( N , 0 , bound ){
  //   FOREQ( M , 0 , bound ){
  //     FOREQ( K , 0 , bound ){
  //   	COUT( N , M , K , ":" , Naive( N , M , K ) );
  //     }
  //   }
  //   // cout << Naive( N ) << ",\n"[N==bound];
  // }
}

inline void SmallTest()
{
  // CEXPR( int , bound , 10 );
  // FOREQ( N , 0 , bound ){
  //   FOREQ( M , 0 , bound ){
  //     FOREQ( K , 0 , bound ){
  //   	COMPARE( N , M , K );
  //     }
  //   }
  //   // COMPARE( N );
  // }
}

REPEAT_MAIN(1);
0