結果
問題 | No.2917 二重木 |
ユーザー | 👑 p-adic |
提出日時 | 2023-10-11 09:52:48 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 579 ms / 3,000 ms |
コード長 | 35,278 bytes |
コンパイル時間 | 3,861 ms |
コンパイル使用メモリ | 240,332 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-13 09:02:06 |
合計ジャッジ時間 | 9,872 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,812 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 3 ms
6,940 KB |
testcase_21 | AC | 17 ms
6,940 KB |
testcase_22 | AC | 53 ms
6,944 KB |
testcase_23 | AC | 102 ms
6,940 KB |
testcase_24 | AC | 141 ms
6,944 KB |
testcase_25 | AC | 174 ms
6,940 KB |
testcase_26 | AC | 244 ms
6,940 KB |
testcase_27 | AC | 370 ms
6,940 KB |
testcase_28 | AC | 445 ms
6,940 KB |
testcase_29 | AC | 569 ms
6,944 KB |
testcase_30 | AC | 571 ms
6,940 KB |
testcase_31 | AC | 572 ms
6,944 KB |
testcase_32 | AC | 573 ms
6,944 KB |
testcase_33 | AC | 579 ms
6,940 KB |
testcase_34 | AC | 577 ms
6,940 KB |
ソースコード
#ifdef DEBUG #define _GLIBCXX_DEBUG #define SIGNAL signal( SIGABRT , &AlertAbort ); #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 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 SIGNAL #define DEXPR( LL , BOUND , VALUE , DEBUG_VALUE ) CEXPR( LL , BOUND , VALUE ) #define ASSERT( A , MIN , MAX ) assert( ( MIN ) <= A && A <= ( MAX ) ) #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; using ld = long double; using lld = __float128; template <typename INT> using T2 = pair<INT,INT>; template <typename INT> using T3 = tuple<INT,INT,INT>; template <typename INT> using T4 = tuple<INT,INT,INT,INT>; #define REPEAT_MAIN( BOUND ) int main(){ ios_base::sync_with_stdio( false ); cin.tie( nullptr ); SIGNAL; DEXPR( int , bound_test_case_num , BOUND , min( BOUND , 100 ) ); int test_case_num = 1; if constexpr( bound_test_case_num > 1 ){ SET_ASSERT( test_case_num , 1 , bound_test_case_num ); } REPEAT( test_case_num ){ if constexpr( bound_test_case_num > 1 ){ CERR( "testcase " , VARIABLE_FOR_REPEAT_test_case_num , ":" ); } Solve(); CERR( "" ); } } #define START_WATCH chrono::system_clock::time_point watch = chrono::system_clock::now() #define CURRENT_TIME static_cast<double>( chrono::duration_cast<chrono::microseconds>( chrono::system_clock::now() - watch ).count() / 1000.0 ) #define CHECK_WATCH( TL_MS ) ( CURRENT_TIME < TL_MS - 100.0 ) #define TYPE_OF( VAR ) decay_t<decltype( VAR )> #define CEXPR( LL , BOUND , VALUE ) constexpr LL BOUND = VALUE #define CIN( LL , ... ) LL __VA_ARGS__; VariadicCin( cin , __VA_ARGS__ ) #define SET_ASSERT( A , MIN , MAX ) cin >> A; ASSERT( A , MIN , MAX ) #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 ) LL A[N]; SET_A( A , N ); #define GETLINE_SEPARATE( SEPARATOR , ... ) string __VA_ARGS__; VariadicGetline( cin , SEPARATOR , __VA_ARGS__ ) #define GETLINE( ... ) 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( ... ) COUT( __VA_ARGS__ ); 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... ); } // デバッグ用 #ifdef DEBUG inline void AlertAbort( int n ) { CERR( "abort関数が呼ばれました。assertマクロのメッセージが出力されていない場合はオーバーフローの有無を確認をしてください。" ); } void AutoCheck( bool& auto_checked ); #endif #define FACTORIAL_MOD( ANSWER , ANSWER_INV , INVERSE , MAX_INDEX , CONSTEXPR_LENGTH , MODULO ) \ ll ANSWER[CONSTEXPR_LENGTH]; \ ll ANSWER_INV[CONSTEXPR_LENGTH]; \ ll INVERSE[CONSTEXPR_LENGTH]; \ { \ ll VARIABLE_FOR_PRODUCT_FOR_FACTORIAL = 1; \ ANSWER[0] = VARIABLE_FOR_PRODUCT_FOR_FACTORIAL; \ FOREQ( i , 1 , MAX_INDEX ){ \ ANSWER[i] = ( VARIABLE_FOR_PRODUCT_FOR_FACTORIAL *= i ) %= ( MODULO ); \ } \ ANSWER_INV[0] = ANSWER_INV[1] = INVERSE[1] = VARIABLE_FOR_PRODUCT_FOR_FACTORIAL = 1; \ FOREQ( i , 2 , MAX_INDEX ){ \ ANSWER_INV[i] = ( VARIABLE_FOR_PRODUCT_FOR_FACTORIAL *= INVERSE[i] = ( MODULO ) - ( ( ( ( MODULO ) / i ) * INVERSE[ ( MODULO ) % i ] ) % ( MODULO ) ) ) %= ( MODULO ); \ } \ } \ // 圧縮用 #define TE template #define TY typename #define US using #define ST static #define IN inline #define CL class #define PU public #define OP operator #define CE constexpr #define CO const #define NE noexcept #define RE return #define WH while #define VO void #define VE vector #define LI list #define BE begin #define EN end #define SZ size #define MO move #define TH this #define CRI CO int& #define CRUI CO uint& #define CRL CO ll& #define SFINAE_FOR_PO(DEFAULT) TY Arg,enable_if_t<is_constructible<T,decay_t<Arg> >::value>* DEFAULT #define DF_BODY_OF_PS_OF_MU_OF_PO_PROTH_MOD(TYPE,ARG,RHS) TE <> PO<TYPE>& PO<TYPE>::OP*=(ARG f){if(m_SZ != 0){VE<TYPE> v{};v.swap(m_f);TRPO<TYPE> TH_copy{m_SZ + f.m_SZ - 1,MO(v)};TH_copy *= RHS;m_f = MO(TH_copy.PO<TYPE>::m_f);m_SZ = m_f.SZ();}RE *TH;} TE <TY T>CL PO{PU:VE<T> m_f;uint m_SZ;PU:IN PO();IN PO(CO T& t);IN PO(T&& t);TE <SFINAE_FOR_PO(= nullptr)> IN PO(CO Arg& n);IN PO(CO PO<T>& f);IN PO(PO<T>&& f);IN PO(CRUI i,CO T& t);IN PO(CRUI i,T&& t);TE <SFINAE_FOR_PO(= nullptr)> IN PO(CRUI i,CO Arg& n);IN PO(CO VE<T>& f);IN PO(VE<T>&& f);IN PO<T>& OP=(CO T& t);IN PO<T>& OP=(T&& t);TE <SFINAE_FOR_PO(= nullptr)> IN PO<T>& OP=(CO Arg& n);IN PO<T>& OP=(CO PO<T>& f);IN PO<T>& OP=(PO<T>&& f);IN PO<T>& OP=(CO VE<T>& f);IN PO<T>& OP=(VE<T>&& f);IN CO T& OP[](CRUI i) CO;IN T& OP[](CRUI i);IN T OP()(CO T& t) CO;PO<T>& OP+=(CO PO<T>& f);PO<T>& OP-=(CO PO<T>& f);PO<T>& OP*=(CO PO<T>& f);PO<T>& OP*=(PO<T>&& f);PO<T>& OP/=(CO T& t);IN PO<T>& OP/=(CO PO<T>& f);PO<T>& OP%=(CO T& t);PO<T>& OP%=(CO PO<T>& f);IN PO<T> OP-() CO;PO<T>& OP<<=(CO T& t);IN CO VE<T>& GetCoefficient() CO NE;IN CRUI SZ() CO NE;IN VO swap(PO<T>& f);IN VO swap(VE<T>& f);VO ReMORedundantZero();IN string Display() CO NE;ST PO<T> Quotient(CO PO<T>& f0,CO PO<T>& f1);ST PO<T> TransposeQuotient(CO PO<T>& f0,CRUI f0_transpose_SZ,CO PO<T>& f1_transpose_inverse,CRUI f1_SZ);ST PO<T> Transpose(CO PO<T>& f,CRUI f_transpose_SZ);ST IN CO PO<T>& zero();ST IN CO T& CO_zero();ST IN CO T& CO_one();ST IN CO T& CO_minus_one();}; #define RE_ZERO_FOR_MU_FOR_TR_PO_IF(CONDITION) if(CONDITION){RE OP=(zero);} #define RE_ZERO_FOR_TR_MU_CO_FOR_TR_PO_IF(CONDITION) if(CONDITION){RE TRPO<T>(m_N);} #define RE_ZERO_FOR__FOR_TR_PO_IF(MU,CONDITION) RE_ZERO_FOR_ ## MU ## _FOR_TR_PO_IF(CONDITION) #define SET_VE_FOR_AN_OF_MU_FOR_TR_PO(N_OUTPUT_LIM) if(PO<T>::m_SZ < N_OUTPUT_LIM){for(uint i = PO<T>::m_SZ;i < N_OUTPUT_LIM;i++){PO<T>::m_f.push_back(0);}PO<T>::m_SZ = N_OUTPUT_LIM;} #define SET_VE_FOR_AN_OF_TR_MU_CO_FOR_TR_PO(N_OUTPUT_LIM) VE<T> AN(N_OUTPUT_LIM) #define SET_VE_FOR_AN_OF__FOR_TR_PO(MU,N_OUTPUT_LIM) SET_VE_FOR_AN_OF_ ## MU ## _FOR_TR_PO(N_OUTPUT_LIM) #define SET_SUM_OF_MU_FOR_TR_PO PO<T>::m_f[i] = sum #define SET_SUM_OF_TR_MU_CO_FOR_TR_PO AN[i] = sum #define SET_SUM_OF__FOR_TR_PO(MU) SET_SUM_OF_ ## MU ## _FOR_TR_PO #define SET_N_INPUT_START_FOR_MU_FOR_TR_PO(F,SZ,N_INPUT_START_NUM) uint N_INPUT_START_NUM{};for(uint i = 0;i < SZ && searching;i++){if(F[i] != zero){N_INPUT_START_NUM = i;searching = false;}} #define SET_N_INPUT_MAX_FOR_MU_FOR_TR_PO(F,SZ,N_INPUT_MAX_NUM) uint N_INPUT_MAX_NUM{};searching = true;for(uint i = (SZ) - 1;searching;i--){if(F[i] != zero){N_INPUT_MAX_NUM = i;searching = false;}} #define CN_FOR_MU_FOR_TR_PO(J_MIN) CO uint j_max = i < N_input_max_0_start_1?i - N_input_start_1:N_input_max_0;T sum{zero};for(uint j = J_MIN;j <= j_max;j++){sum += PO<T>::m_f[j] * f.PO<T>::m_f[i - j];}PO<T>::m_f[i] = sum; #define CN_FOR_TR_MU_CO_FOR_TR_PO(J_MIN) CO uint j_max = i < N_input_max_0_start_1?i - N_input_start_1:N_input_max_0;T& m_fi = AN[i];for(uint j = J_MIN;j <= j_max;j++){m_fi += PO<T>::m_f[j] * f.PO<T>::m_f[i - j];} #define CN_FOR__FOR_TR_PO(MU,J_MIN) CN_FOR_ ## MU ## _FOR_TR_PO(J_MIN) #define ZEROIFICATION_FOR_MU_FOR_TR_PO for(uint i = 0;i < N_input_start_0_start_1;i++){PO<T>::m_f[i] = 0;} #define ZEROIFICATION_FOR_TR_MU_CO_FOR_TR_PO CRUI N_output_start_fixed = N_output_start < N_input_start_0_start_1?N_output_start:N_input_start_0_start_1;for(uint i = 0;i < N_output_start_fixed;i++){AN[i] = 0;} #define ZEROIFICATION_FOR__FOR_TR_PO(MU) ZEROIFICATION_FOR_ ## MU ## _FOR_TR_PO #define DF_0_OF__FOR_TR_PO(MU,ACCESS_ENTRY,N_OUTPUT_START) RE_ZERO_FOR__FOR_TR_PO_IF(MU,PO<T>::m_SZ == 0);uint N_output_max = PO<T>::m_SZ + f.PO<T>::m_SZ - 2;if(N_output_max >= m_N){N_output_max = m_N - 1;}CO uint N_output_lim = N_output_max + 1;SET_VE_FOR_AN_OF__FOR_TR_PO(MU,N_output_lim);for(uint i = N_output_max;searching;i--){T sum{zero};for(uint j = 0;j <= i;j++){sum += ACCESS_ENTRY * f.PO<T>::OP[](i - j);}SET_SUM_OF__FOR_TR_PO(MU);searching = i > N_OUTPUT_START;} #define DF_1_OF__FOR_TR_PO(MU) SET_N_INPUT_START_FOR_MU_FOR_TR_PO(PO<T>::m_f,PO<T>::m_SZ,N_input_start_0);RE_ZERO_FOR__FOR_TR_PO_IF(MU,searching);searching = true;SET_N_INPUT_START_FOR_MU_FOR_TR_PO(f,f.PO<T>::m_SZ,N_input_start_1); #define SET_N_INPUT_RANGE SET_N_INPUT_MAX_FOR_MU_FOR_TR_PO(PO<T>::m_f,PO<T>::m_SZ,N_input_max_0);SET_N_INPUT_MAX_FOR_MU_FOR_TR_PO(f,f.PO<T>::m_SZ < m_N?f.PO<T>::m_SZ:m_N,N_input_max_1);CO uint N_input_max_0_max_1 = N_input_max_0 + N_input_max_1;CO uint N_input_start_0_start_1 = N_input_start_0 + N_input_start_1;uint N_output_lim_fixed = N_input_max_0_max_1 < m_N?N_input_max_0_max_1 + 1:m_N; #define DF_3_OF__FOR_TR_PO(MU) CO uint N_input_start_0_max_1 = N_input_start_0 + N_input_max_1;CO uint N_input_max_0_start_1 = N_input_max_0 + N_input_start_1;CO uint N_output_max_fixed = N_output_lim_fixed - 1;SET_VE_FOR_AN_OF__FOR_TR_PO(MU,N_output_lim_fixed);for(uint i = N_output_max_fixed;i > N_input_start_0_max_1;i--){CN_FOR__FOR_TR_PO(MU,i - N_input_max_1);}searching = true;for(uint i = N_input_start_0_max_1 < N_output_max_fixed?N_input_start_0_max_1:N_output_max_fixed;searching;i--){CN_FOR__FOR_TR_PO(MU,N_input_start_0);searching = i > N_input_start_0_start_1;}ZEROIFICATION_FOR__FOR_TR_PO(MU); #define SET_SHIFTED_VE_FOR_MU(V,F,I_START,I_MAX,I_SHIFT) VE<T> V(product_LE);for(uint i = I_START;i <= I_MAX;i++){V[I_SHIFT + i] = F[i];} #define DF_OF_MU_FOR_TR_PO(RE_LINE_0,RE_LINE_1,RE_LINE_2,RE_LINE_3,RE_LINE_4,MU,ACCESS_ENTRY,N_OUTPUT_START,FIX_N_OUTPUT_LIM) CE CRUI border_0 = FFT_MU_border_0<T>;CO T& zero = PO<T>::CO_zero();bool searching = true;if(PO<T>::m_SZ < border_0 && f.PO<T>::m_SZ < border_0){RE_LINE_0;DF_0_OF__FOR_TR_PO(MU,ACCESS_ENTRY,N_OUTPUT_START);RE_LINE_1;}DF_1_OF__FOR_TR_PO(MU);RE_LINE_2;SET_N_INPUT_RANGE;FIX_N_OUTPUT_LIM;RE_LINE_3;DF_3_OF__FOR_TR_PO(MU);RE_LINE_4; #define DF_OF_INVERSE_FOR_TR_PO(TYPE,RECURSION) CRUI N = f.GetTruncation();uint PW;uint PW_2 = 1;TRPO< TYPE > f_inv{PW_2,PO< TYPE >::CO_one() / f[0]};WH(PW_2 < N){PW = PW_2;PW_2 *= 2;f_inv.SetTruncation(PW_2);RECURSION;}f_inv.SetTruncation(N);RE f_inv #define DF_OF_EXP_FOR_TR_PO(TYPE,RECURSION) CRUI N = f.GetTruncation();uint PW;uint PW_2 = 1;TRPO< TYPE > f_exp{PW_2,PO< TYPE >::CO_one()};WH(PW_2 < N){PW = PW_2;PW_2 *= 2;f_exp.SetTruncation(PW_2);RECURSION;}f_exp.SetTruncation(N);RE f_exp TE <TY T>CL TRPO :PU PO<T>{PU:uint m_N;PU:IN TRPO(CRUI N = 0);IN TRPO(CO TRPO<T>& f);IN TRPO(TRPO<T>&& f);IN TRPO(CRUI N,CO T& t);IN TRPO(CRUI N,CO PO<T>& f);IN TRPO(CRUI N,PO<T>&& f);IN TRPO(CRUI N,CRUI i,CO T& t);IN TRPO(CRUI N,CRUI i,T&& t);TE <SFINAE_FOR_PO(= nullptr)> IN TRPO(CRUI N,CRUI i,CO Arg& t);IN TRPO(CRUI N,VE<T>&& f);IN TRPO<T>& OP=(CO TRPO<T>& f);IN TRPO<T>& OP=(TRPO<T>&& f);IN TRPO<T>& OP=(CO T& t);IN TRPO<T>& OP=(T&& t);TE <SFINAE_FOR_PO(= nullptr)> IN TRPO<T>& OP=(CO Arg& n);IN TRPO<T>& OP=(CO PO<T>& f);IN TRPO<T>& OP=(PO<T>&& f);IN TRPO<T>& OP+=(CO T& t);IN TRPO<T>& OP+=(CO PO<T>& f);IN TRPO<T>& OP+=(CO TRPO<T>& f);TRPO<T>& TRPlus(CO PO<T>& f,CRUI N_input_start,CRUI N_input_limit);IN TRPO<T>& OP-=(CO T& t);IN TRPO<T>& OP-=(CO PO<T>& f);IN TRPO<T>& OP-=(CO TRPO<T>& f);TRPO<T>& TRMinus(CO PO<T>& f,CRUI N_input_start,CRUI N_input_limit);IN TRPO<T>& OP*=(CO T& t);TRPO<T>& OP*=(CO PO<T>& f);IN TRPO<T>& OP*=(PO<T>&& f);TRPO<T>& TRMU(CO PO<T>& f,CRUI N_output_start,CRUI N_output_lim);TRPO<T> TRMU_CO(CO PO<T>& f,CRUI N_output_start,CRUI N_output_lim) CO;IN TRPO<T>& OP/=(CO T& t);IN TRPO<T>& OP/=(CO TRPO<T>& t);IN TRPO<T>& OP%=(CO T& t);IN TRPO<T> OP-() CO;IN VO SetTruncation(CRUI N)NE;IN CRUI GetTruncation() CO NE;IN TRPO<T>& TruncateInitial(CRUI N)NE;IN TRPO<T>& TruncateFinal(CRUI N)NE;};TE <TY T> CE CO uint FFT_MU_border_0 = 17; TE <TY T> IN TRPO<T>::TRPO(CRUI N):PO<T>(),m_N(N){PO<T>::m_f.reserve(m_N);}TE <TY T> IN TRPO<T>::TRPO(CO TRPO<T>& f):PO<T>(f),m_N(f.m_N){PO<T>::m_f.reserve(m_N);}TE <TY T> IN TRPO<T>::TRPO(TRPO<T>&& f):PO<T>(MO(f)),m_N(MO(f.m_N)){PO<T>::m_f.reserve(m_N);}TE <TY T> IN TRPO<T>::TRPO(CRUI N,CO T& t):PO<T>(t),m_N(N){PO<T>::m_f.reserve(m_N);}TE <TY T> IN TRPO<T>::TRPO(CRUI N,CO PO<T>& f):PO<T>(),m_N(N){PO<T>::m_SZ = f.PO<T>::m_SZ < m_N?f.PO<T>::m_SZ:m_N;PO<T>::m_f = VE<T>(PO<T>::m_SZ);for(uint i = 0;i < PO<T>::m_SZ;i++){PO<T>::m_f[i] = f.PO<T>::m_f[i];}PO<T>::m_f.reserve(m_N);}TE <TY T> IN TRPO<T>::TRPO(CRUI N,PO<T>&& f):PO<T>(),m_N(N){if(f.PO<T>::m_SZ < m_N * 2){PO<T>::OP=(MO(f));if(f.PO<T>::m_SZ < m_N){PO<T>::m_f.reserve(m_N);}else{TruncateFinal(m_N);}}else{PO<T>::m_f = VE<T>(m_N);for(uint i = 0;i < m_N;i++){PO<T>::m_f[i] = MO(f.PO<T>::m_f[i]);}PO<T>::m_SZ = m_N;}}TE <TY T> IN TRPO<T>::TRPO(CRUI N,CRUI i,CO T& t):PO<T>(),m_N(N){if(i < m_N?t != PO<T>::CO_zero():false){PO<T>::OP[](i) = t;}PO<T>::m_f.reserve(m_N);}TE <TY T> IN TRPO<T>::TRPO(CRUI N,CRUI i,T&& t):PO<T>(),m_N(N){if(i < m_N?t != PO<T>::CO_zero():false){PO<T>::OP[](i) = MO(t);}PO<T>::m_f.reserve(m_N);}TE <TY T> TE <SFINAE_FOR_PO()> IN TRPO<T>::TRPO(CRUI N,CRUI i,CO Arg& n):TRPO(N,i,T(n)){}TE <TY T> IN TRPO<T>::TRPO(CRUI N,VE<T>&& f):PO<T>(),m_N(N){CO uint f_SZ = f.SZ();if(f_SZ < m_N * 2){PO<T>::OP=(MO(f));if(f_SZ < m_N){PO<T>::m_f.reserve(m_N);}else{TruncateFinal(m_N);}}else{PO<T>::m_f = VE<T>(m_N);for(uint i = 0;i < m_N;i++){PO<T>::m_f[i] = MO(f[i]);}PO<T>::m_f.reserve(m_N);}} TE <TY T> IN TRPO<T>& TRPO<T>::OP=(CO TRPO<T>& f){PO<T>::OP=(f);m_N = f.m_N;PO<T>::m_f.reserve(m_N);RE *TH;} TE <TY T> IN TRPO<T>& TRPO<T>::OP=(TRPO<T>&& f){PO<T>::OP=(MO(f));m_N = MO(f.m_N);PO<T>::m_f.reserve(m_N);RE *TH;} TE <TY T> IN TRPO<T>& TRPO<T>::OP=(CO T& t){PO<T>::OP=(t);RE *TH;} TE <TY T> IN TRPO<T>& TRPO<T>::OP=(T&& t){PO<T>::OP=(MO(t));RE *TH;} TE <TY T> TE <SFINAE_FOR_PO()> IN TRPO<T>& TRPO<T>::OP=(CO Arg& n){PO<T>::OP=(T(n));RE *TH;} TE <TY T> IN TRPO<T>& TRPO<T>::OP=(CO PO<T>& f){RE OP=(TRPO<T>(m_N,f));} TE <TY T> IN TRPO<T>& TRPO<T>::OP=(PO<T>&& f){RE OP=(TRPO<T>(m_N,MO(f)));} TE <TY T> IN TRPO<T>& TRPO<T>::OP+=(CO T& t){PO<T>::OP+=(t);RE *TH;}TE <TY T> IN TRPO<T>& TRPO<T>::OP+=(CO PO<T>& f){RE TRPO<T>::TRPlus(f,0,f.m_SZ);}TE <TY T> IN TRPO<T>& TRPO<T>::OP+=(CO TRPO<T>& f){RE m_N == 0?OP=(f):TRPO<T>::TRPlus(f,0,f.PO<T>::m_SZ);}TE <TY T>TRPO<T>& TRPO<T>::TRPlus(CO PO<T>& f,CRUI N_input_start,CRUI N_input_lim){CRUI SZ = N_input_lim < m_N?N_input_lim < f.PO<T>::m_SZ?N_input_lim:f.PO<T>::m_SZ:m_N < f.PO<T>::m_SZ?m_N:f.PO<T>::m_SZ;if(PO<T>::m_SZ < SZ){PO<T>::m_f.reserve(SZ);for(uint i = N_input_start;i < PO<T>::m_SZ;i++){PO<T>::m_f[i] += f.PO<T>::m_f[i];}for(uint i = PO<T>::m_SZ;i < SZ;i++){PO<T>::m_f.push_back(f.PO<T>::m_f[i]);}PO<T>::m_SZ = SZ;}else{for(uint i = N_input_start;i < SZ;i++){PO<T>::m_f[i] += f.PO<T>::m_f[i];}}RE *TH;}TE <TY T> IN TRPO<T>& TRPO<T>::OP-=(CO T& t){PO<T>::OP-=(t);RE *TH;}TE <TY T> IN TRPO<T>& TRPO<T>::OP-=(CO PO<T>& f){RE TRPO<T>::TRMinus(f,0,f.m_SZ);}TE <TY T> IN TRPO<T>& TRPO<T>::OP-=(CO TRPO<T>& f){RE m_N == 0?OP=(-f):TRPO<T>::TRMinus(f,0,f.PO<T>::m_SZ);}TE <TY T>TRPO<T>& TRPO<T>::TRMinus(CO PO<T>& f,CRUI N_input_start,CRUI N_input_lim){CRUI SZ = N_input_lim < m_N?N_input_lim < f.PO<T>::m_SZ?N_input_lim:f.PO<T>::m_SZ:m_N < f.PO<T>::m_SZ?m_N:f.PO<T>::m_SZ;if(PO<T>::m_SZ < SZ){PO<T>::m_f.reserve(SZ);for(uint i = N_input_start;i < PO<T>::m_SZ;i++){PO<T>::m_f[i] -= f.PO<T>::m_f[i];}for(uint i = PO<T>::m_SZ;i < SZ;i++){PO<T>::m_f.push_back(- f.PO<T>::m_f[i]);}PO<T>::m_SZ = SZ;}else{for(uint i = N_input_start;i < SZ;i++){PO<T>::m_f[i] -= f.PO<T>::m_f[i];}}RE *TH;}TE <TY T> IN TRPO<T>& TRPO<T>::OP*=(CO T& t){PO<T>::OP*=(t);RE *TH;}TE <TY T>TRPO<T>& TRPO<T>::OP*=(CO PO<T>& f){DF_OF_MU_FOR_TR_PO(RE_ZERO_FOR_MU_FOR_TR_PO_IF(f.PO<T>::m_SZ == 0),RE *TH,RE_ZERO_FOR_MU_FOR_TR_PO_IF(searching),RE_ZERO_FOR_MU_FOR_TR_PO_IF(N_input_start_0_start_1 >= m_N),RE *TH,MU,PO<T>::m_f[j],0,);}TE <TY T> IN TRPO<T>& TRPO<T>::OP*=(PO<T>&& f){RE OP*=(f);}TE <TY T>TRPO<T>& TRPO<T>::TRMU(CO PO<T>& f,CRUI N_output_start,CRUI N_output_lim){DF_OF_MU_FOR_TR_PO(,RE *TH,,RE_ZERO_FOR_MU_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE *TH,MU,PO<T>::m_f[j],N_output_start,if(N_output_lim_fixed > N_output_lim){N_output_lim_fixed = N_output_lim;});}TE <TY T>TRPO<T> TRPO<T>::TRMU_CO(CO PO<T>& f,CRUI N_output_start,CRUI N_output_lim) CO{DF_OF_MU_FOR_TR_PO(,RE TRPO<T>(m_N,MO(AN)),,RE_ZERO_FOR_TR_MU_CO_FOR_TR_PO_IF(N_input_start_0_start_1 >= N_output_lim_fixed),RE TRPO<T>(m_N,MO(AN)),TR_MU_CO,PO<T>::OP[](j),N_output_start,if(N_output_lim_fixed > N_output_lim){N_output_lim_fixed = N_output_lim;});}TE <TY T> IN TRPO<T>& TRPO<T>::OP/=(CO T& t){PO<T>::OP/=(t);RE *TH;}TE <TY T> IN TRPO<T>& TRPO<T>::OP/=(CO TRPO<T>& f){RE OP*=(Inverse(m_N > f.m_N?f:TRPO<T>(m_N,f)));}TE <TY T> IN TRPO<T>& TRPO<T>::OP%=(CO T& t){PO<T>::OP%=(t);RE *TH;}TE <TY T> IN TRPO<T> TRPO<T>::OP-() CO{RE MO(TRPO<T>(m_N) -= *TH);}TE <TY T> IN VO TRPO<T>::SetTruncation(CRUI N)NE{if(N < m_N){TruncateFinal(m_N);}else{PO<T>::m_f.reserve(N);}m_N = N;}TE <TY T> IN CRUI TRPO<T>::GetTruncation() CO NE{RE m_N;}TE <TY T> IN TRPO<T>& TRPO<T>::TruncateInitial(CRUI N)NE{CRUI SZ = N < PO<T>::m_SZ?N:PO<T>::m_SZ;for(uint i = 0;i < SZ;i++){PO<T>::m_f[i] = 0;}RE *TH;}TE <TY T> IN TRPO<T>& TRPO<T>::TruncateFinal(CRUI N)NE{WH(PO<T>::m_SZ > N){PO<T>::m_f.pop_back();PO<T>::m_SZ--;}RE *TH;}TE <TY T,TY P> IN TRPO<T> OP+(CO TRPO<T>& f0,CO P& f1){RE MO(TRPO<T>(f0) += f1);}TE <TY T,TY P> IN TRPO<T> OP-(CO TRPO<T>& f){RE MO(TRPO<T>(f.GetTurncation()) -= f);}TE <TY T,TY P> IN TRPO<T> OP-(CO TRPO<T>& f0,CO P& f1){RE MO(TRPO<T>(f0) -= f1);}TE <TY T,TY P> IN TRPO<T> OP*(CO TRPO<T>& f0,CO P& f1){RE MO(TRPO<T>(f0) *= f1);}TE <TY T,TY P> IN TRPO<T> OP/(CO TRPO<T>& f0,CO P& f1){RE MO(TRPO<T>(f0) /= f1);}TE <TY T> IN TRPO<T> OP%(CO TRPO<T>& f0,CO T& t1){RE MO(TRPO<T>(f0) %= t1);}TE <TY T>TRPO<T> Differential(CRUI n,CO TRPO<T>& f){if(f.PO<T>::m_SZ < n){RE TRPO<T>(f.m_N - n,PO<T>::zero());}VE<T> df(f.PO<T>::m_SZ - n);T coef = T::Factorial(n);uint i = n;WH(i < f.PO<T>::m_SZ){df[i - n] = f[i] * coef;i++;(coef *= i) /= (i - n);}RE TRPO<T>(f.m_N - n,MO(df));}TE <TY T>TRPO<T> TRDifferential(CO TRPO<T>& f,CRUI N_output_start_plus_one){assert(f.m_N > 0);TRPO<T> f_dif{f.m_N - 1};if(N_output_start_plus_one < f.PO<T>::m_SZ){CO uint SZ = f.PO<T>::m_SZ - 1;f_dif.PO<T>::m_f = VE<T>(SZ);for(uint i = N_output_start_plus_one;i < f.PO<T>::m_SZ;i++){f_dif.PO<T>::m_f[i-1] = f.PO<T>::m_f[i] * i;}f_dif.PO<T>::m_SZ = SZ;}RE f_dif;}TE <TY T> IN TRPO<T> Differential(CO TRPO<T>& f){RE TRDifferential<T>(f,1);}TE <TY T>TRPO<T> TRIntegral(CO TRPO<T>& f,CRUI N_output_start){TRPO<T> f_int{f.m_N + 1};if(N_output_start <= f.PO<T>::m_SZ){CO uint SZ = f.PO<T>::m_SZ + 1;f_int.PO<T>::m_f = VE<T>(SZ);for(uint i = N_output_start;i <= f.PO<T>::m_SZ;i++){f_int.PO<T>::m_f[i] = f.PO<T>::m_f[i - 1] / T(i);}f_int.PO<T>::m_SZ = SZ;}RE f_int;}TE <TY T> IN TRPO<T> Integral(CO TRPO<T>& f){RE TRIntegral<T>(f,1);}TE <TY T>TRPO<T> Inverse(CO TRPO<T>& f){DF_OF_INVERSE_FOR_TR_PO(T,f_inv.TRMinus(f_inv.TRMU_CO(f,PW,PW_2).TRMU(f_inv,PW,PW_2),PW,PW_2));}TE <TY T>TRPO<T> Exp(CO TRPO<T>& f){DF_OF_EXP_FOR_TR_PO(T,f_exp.TRMinus((TRIntegral(Differential(f_exp).TRMU_CO(Inverse(f_exp),PW - 1,PW_2),PW).TRMinus(f,PW,PW_2)).TRMU(f_exp,PW),PW,PW_2));}TE <TY T> IN TRPO<T> Log(CO TRPO<T>& f){RE Integral<T>(Differential<T>(f) /= f);}TE <TY T> IN TRPO<T> PW(CO TRPO<T>& f,CO T& t){RE Exp(Log(f) *= t);} TE <TY T> IN PO<T>::PO():m_f(),m_SZ(0){}TE <TY T> IN PO<T>::PO(CO T& t):PO(){if(t != CO_zero()){OP[](0) = t;}}TE <TY T> IN PO<T>::PO(T&& t):PO(){if(t != CO_zero()){OP[](0) = MO(t);}}TE <TY T> TE <SFINAE_FOR_PO()> IN PO<T>::PO(CO Arg& n):PO(T(n)){}TE <TY T> IN PO<T>::PO(CO PO<T>& f):m_f(f.m_f),m_SZ(f.m_SZ){}TE <TY T> IN PO<T>::PO(PO<T>&& f):m_f(MO(f.m_f)),m_SZ(MO(f.m_SZ)){}TE <TY T> IN PO<T>::PO(CRUI i,CO T& t):PO(){if(t != CO_zero()){OP[](i) = t;}}TE <TY T> IN PO<T>::PO(CRUI i,T&& t):PO(){if(t != CO_zero()){OP[](i) = MO(t);}}TE <TY T> TE <SFINAE_FOR_PO()> IN PO<T>::PO(CRUI i,CO Arg& n):PO(i,T(n)){}TE <TY T> IN PO<T>::PO(CO VE<T>& f):m_f(f),m_SZ(m_f.SZ()){}TE <TY T> IN PO<T>::PO(VE<T>&& f):m_f(MO(f)),m_SZ(m_f.SZ()){}TE <TY T> IN PO<T>& PO<T>::OP=(CO T& t){m_f.clear();m_SZ = 0;OP[](0) = t;RE *TH;}TE <TY T> IN PO<T>& PO<T>::OP=(T&& t){m_f.clear();m_SZ = 0;OP[](0) = MO(t);RE *TH;}TE <TY T> TE <SFINAE_FOR_PO()> IN PO<T>& PO<T>::OP=(CO Arg& n){RE OP=(T(n));}TE <TY T> IN PO<T>& PO<T>::OP=(CO PO<T>& f){m_f = f.m_f;m_SZ = f.m_SZ;RE *TH;}TE <TY T> IN PO<T>& PO<T>::OP=(PO<T>&& f){m_f = MO(f.m_f);m_SZ = MO(f.m_SZ);RE *TH;}TE <TY T> IN PO<T>& PO<T>::OP=(CO VE<T>& f){m_f = f;m_SZ = f.m_SZ;RE *TH;}TE <TY T> IN PO<T>& PO<T>::OP=(VE<T>&& f){m_f = MO(f);m_SZ = m_f.SZ();RE *TH;}TE <TY T>CO T& PO<T>::OP[](CRUI i) CO{if(m_SZ <= i){RE CO_zero();}RE m_f[i];}TE <TY T> IN T& PO<T>::OP[](CRUI i){if(m_SZ <= i){CO T& z = CO_zero();WH(m_SZ <= i){m_f.push_back(z);m_SZ++;}}RE m_f[i];}TE <TY T> IN T PO<T>::OP()(CO T& t) CO{RE MO((*TH % (PO<T>(1,CO_one()) - t))[0]);}TE <TY T>PO<T>& PO<T>::OP+=(CO PO<T>& f){for(uint i = 0;i < f.m_SZ;i++){OP[](i) += f.m_f[i];}RE *TH;}TE <TY T>PO<T>& PO<T>::OP-=(CO PO<T>& f){for(uint i = 0;i < f.m_SZ;i++){OP[](i) -= f.m_f[i];}RE *TH;}TE <TY T>PO<T>& PO<T>::OP*=(CO PO<T>& f){if(m_SZ == 0){RE *TH;}if(f.m_SZ == 0){m_f.clear();m_SZ = 0;RE *TH;}CO uint SZ = m_SZ + f.m_SZ - 1;PO<T> product{};for(uint i = 0;i < SZ;i++){T& product_i = product[i];CO uint j_min = m_SZ <= i?i - m_SZ + 1:0;CO uint j_lim = i < f.m_SZ?i + 1:f.m_SZ;for(uint j = j_min;j < j_lim;j++){product_i += m_f[i - j] * f.m_f[j];}}RE OP=(MO(product));}TE <TY T> IN PO<T>& PO<T>::OP*=(PO<T>&& f){RE OP*=(f);};TE <TY T>PO<T>& PO<T>::OP/=(CO T& t){if(t == CO_one()){RE *TH;}CO T t_inv{CO_one() / t};for(uint i = 0;i < m_SZ;i++){OP[](i) *= t_inv;}RE *TH;}TE <TY T> IN PO<T>& PO<T>::OP/=(CO PO<T>& f){RE m_SZ < f.m_SZ?*TH:OP=(Quotient(*TH,f));}TE <TY T>PO<T> PO<T>::Quotient(CO PO<T>& f0,CO PO<T>& f1){if(f0.m_SZ < f1.m_SZ){RE f0;}assert(f1.m_SZ > 0);CO uint f0_transpose_SZ = f0.m_SZ - f1.m_SZ + 1;CO uint f1_transpose_SZ = f0_transpose_SZ < f1.m_SZ?f0_transpose_SZ:f1.m_SZ;RE TransposeQuotient(f0,f0_transpose_SZ,Inverse(TRPO<T>(f0_transpose_SZ,Transpose(f1,f1_transpose_SZ))),f1.m_SZ);}TE <TY T>PO<T> PO<T>::TransposeQuotient(CO PO<T>& f0,CRUI f0_transpose_SZ,CO PO<T>& f1_transpose_inverse,CRUI f1_SZ){TRPO<T> f0_transpose{f0_transpose_SZ,Transpose(f0,f0_transpose_SZ)};f0_transpose *= f1_transpose_inverse;for(uint d0 = (f0_transpose_SZ + 1) / 2;d0 < f0_transpose_SZ;d0++){::swap(f0_transpose.PO<T>::m_f[d0],f0_transpose.PO<T>::m_f[ f0_transpose_SZ - 1 - d0 ]);}RE f0_transpose;}TE <TY T>PO<T> PO<T>::Transpose(CO PO<T>& f,CRUI f_transpose_SZ){VE<T> f_transpose(f_transpose_SZ);for(uint d = 0;d < f_transpose_SZ;d++){f_transpose[d] = f.m_f[f.m_SZ - 1 - d];}RE PO<T>(MO(f_transpose));}TE <TY T>PO<T>& PO<T>::OP%=(CO T& t){if(t == CO_one()){RE OP=(zero());}for(uint i = 0;i < m_SZ;i++){m_f[i] %= t;}RE *TH;}TE <TY T>PO<T>& PO<T>::OP%=(CO PO<T>& f){if(m_SZ >= f.m_SZ){OP-=((*TH / f) * f);ReMORedundantZero();}RE *TH;}TE <TY T> IN PO<T> PO<T>::OP-() CO{RE MO(PO<T>() -= *TH);}TE <TY T >PO<T>& PO<T>::OP<<=(CO T& t){if(m_SZ > 0){for(uint d = 0;d < m_SZ;d++){m_f[d] *= T::Factorial(d);}TRPO<T> exp_t_transpose{m_SZ * 2};T PW_t = CO_one();for(uint d = 0;d < m_SZ;d++){exp_t_transpose[m_SZ - 1 - d] = PW_t * T::FactorialInverse(d);PW_t *= t;}exp_t_transpose *= *TH;for(uint d = 0;d < m_SZ;d++){m_f[d] = exp_t_transpose.PO<T>::m_f[d + m_SZ - 1] * T::FactorialInverse(d);}}RE *TH;}TE <TY T> IN CO VE<T>& PO<T>::GetCoefficient() CO NE{RE m_f;}TE <TY T> IN CRUI PO<T>::SZ() CO NE{RE m_SZ;}TE <TY T> IN VO PO<T>::swap(PO<T>& f){m_f.swap(f.m_f);swap(m_SZ,f.m_SZ);}TE <TY T> IN VO PO<T>::swap(VE<T>& f){m_f.swap(f);m_SZ = m_f.SZ();}TE <TY T>VO PO<T>::ReMORedundantZero(){CO T& z = CO_zero();WH(m_SZ > 0?m_f[m_SZ - 1] == z:false){m_f.pop_back();m_SZ--;}RE;}TE <TY T>string PO<T>::Display() CO NE{string s = "(";if(m_SZ > 0){s += to_string(m_f[0]);for(uint i = 1;i < m_SZ;i++){s += "," + to_string(m_f[i]);}}s += ")";RE s;}TE <TY T> IN CO PO<T>& PO<T>::zero(){ST CO PO<T> z{};RE z;}TE <TY T> IN CO T& PO<T>::CO_zero(){ST CO T z{0};RE z;}TE <TY T> IN CO T& PO<T>::CO_one(){ST CO T o{1};RE o;}TE <TY T> IN CO T& PO<T>::CO_minus_one(){ST CO T m{-1};RE m;}TE <TY T>bool OP==(CO PO<T>& f0,CO T& t1){CRUI SZ = f0.SZ();CO T& zero = PO<T>::CO_zero();for(uint i = 1;i < SZ;i++){if(f0[i] != zero){RE false;}}RE f0[0] == t1;}TE <TY T>bool OP==(CO PO<T>& f0,CO PO<T>& f1){CRUI SZ0 = f0.SZ();CRUI SZ1 = f1.SZ();CRUI SZ = SZ0 < SZ1?SZ1:SZ0;for(uint i = 0;i < SZ;i++){if(f0[i] != f1[i]){RE false;}}RE true;}TE <TY T,TY P> IN bool OP!=(CO PO<T>& f0,CO P& f1){RE !(f0 == f1);}TE <TY T,TY P> IN PO<T> OP+(CO PO<T>& f0,CO P& f1){RE MO(PO<T>(f0) += f1);}TE <TY T,TY P> IN PO<T> OP-(CO PO<T>& f){RE PO<T>::zero() - f;}TE <TY T,TY P> IN PO<T> OP-(CO PO<T>& f0,CO P& f1){RE MO(PO<T>(f0) -= f1);}TE <TY T,TY P> IN PO<T> OP*(CO PO<T>& f0,CO P& f1){RE MO(PO<T>(f0) *= f1);}TE <TY T> IN PO<T> OP/(CO PO<T>& f0,CO T& t1){RE MO(PO<T>(f0) /= t1);}TE <TY T> IN PO<T> OP/(CO PO<T>& f0,CO PO<T>& f1){RE PO<T>::Quotient(f0,f1);}TE <TY T,TY P> IN PO<T> OP%(CO PO<T>& f0,CO P& f1){RE MO(PO<T>(f0) %= f1);}TE <TY T> PO<T> OP<<(CO PO<T>& f,CO T& t){RE MO(PO<T>(f) <<= t);};TE <TY T,TE <TY...> TY V>T& Prod(V<T>& f){if(f.empty()){f.push_back(T(1));}if(f.SZ() == 1){RE f.front();}auto IT = f.BE(),EN = f.EN();WH(IT != EN){T& t = *IT;IT++;if(IT != EN){t *= *IT;IT = f.erase(IT);}}RE Prod(f);} template <typename INT> class QuotientRing { protected: INT m_n; const INT* m_p_M; public: inline QuotientRing() noexcept; inline QuotientRing( const INT& n , const INT* const & p_M = nullptr ) noexcept; inline QuotientRing( const QuotientRing<INT>& n ) noexcept; inline QuotientRing<INT>& operator+=( const QuotientRing<INT>& n ) noexcept; inline QuotientRing<INT>& operator+=( const INT& n ) noexcept; // operator<が定義されていても負の数は正に直さず剰余を取ることに注意。 inline QuotientRing<INT>& operator-=( const QuotientRing<INT>& n ) noexcept; inline QuotientRing<INT>& operator-=( const INT& n ) noexcept; inline QuotientRing<INT>& operator*=( const QuotientRing<INT>& n ) noexcept; inline QuotientRing<INT>& operator*=( const INT& n ) noexcept; inline const INT& Represent() const noexcept; inline const INT& GetModulo() const noexcept; // m_nの正負やm_p_Mの一致込みの等号。 static inline bool Equal( const QuotientRing<INT>& n0 , const QuotientRing<INT>& n1 ) noexcept; template <typename T> static QuotientRing<INT> Power( const QuotientRing<INT>& n , T exponent ); }; template <typename INT> inline bool operator==( const QuotientRing<INT>& n0 , const QuotientRing<INT>& n1 ) noexcept; template <typename INT> inline bool operator!=( const QuotientRing<INT>& n0 , const QuotientRing<INT>& n1 ) noexcept; template <typename INT , typename T> inline QuotientRing<INT> operator+( const QuotientRing<INT>& n0 , const T& n1 ) noexcept; template <typename INT , typename T> inline QuotientRing<INT> operator-( const QuotientRing<INT>& n0 , const T& n1 ) noexcept; template <typename INT , typename T> inline QuotientRing<INT> operator*( const QuotientRing<INT>& n0 , const T& n1 ) noexcept; template <typename INT , typename T> inline QuotientRing<INT> Power( const QuotientRing<INT>& n , T exponent ); template <typename INT> inline QuotientRing<INT>::QuotientRing() noexcept : m_n() , m_p_M( nullptr ) {} template <typename INT> inline QuotientRing<INT>::QuotientRing( const INT& n , const INT* const & p_M ) noexcept : m_n( p_M == nullptr ? n : n % *p_M ) , m_p_M( p_M ) {} template <typename INT> inline QuotientRing<INT>::QuotientRing( const QuotientRing<INT>& n ) noexcept : m_n( n.m_n ) , m_p_M( n.m_p_M ) {} template <typename INT> inline QuotientRing<INT>& QuotientRing<INT>::operator+=( const QuotientRing<INT>& n ) noexcept { if( m_p_M == nullptr ){ m_p_M = n.m_p_M; } m_n += n.m_n; if( m_p_M != nullptr ){ m_n %= *m_p_M; } return *this; } template <typename INT> inline QuotientRing<INT>& QuotientRing<INT>::operator+=( const INT& n ) noexcept { m_n += n; if( m_p_M != nullptr ){ m_n %= *m_p_M; } return *this; } template <typename INT> inline QuotientRing<INT>& QuotientRing<INT>::operator-=( const QuotientRing<INT>& n ) noexcept { if( m_p_M == nullptr ){ m_p_M = n.m_p_M; } m_n -= n.m_n; if( m_p_M != nullptr ){ m_n %= *m_p_M; } return *this; } template <typename INT> inline QuotientRing<INT>& QuotientRing<INT>::operator-=( const INT& n ) noexcept { m_n -= n; if( m_p_M != nullptr ){ m_n %= *m_p_M; } return *this; } template <typename INT> inline QuotientRing<INT>& QuotientRing<INT>::operator*=( const QuotientRing<INT>& n ) noexcept { if( m_p_M == nullptr ){ m_p_M = n.m_p_M; } m_n *= n.m_n; if( m_p_M != nullptr ){ m_n %= *m_p_M; } return *this; } template <typename INT> inline QuotientRing<INT>& QuotientRing<INT>::operator*=( const INT& n ) noexcept { m_n *= n; if( m_p_M != nullptr ){ m_n %= *m_p_M; } return *this; } template <typename INT> inline const INT& QuotientRing<INT>::Represent() const noexcept { return m_n; } template <typename INT> inline const INT& QuotientRing<INT>::GetModulo() const noexcept { static const INT zero{ 0 }; return m_p_M == nullptr ? zero : *m_p_M; } template <typename INT> inline bool QuotientRing<INT>::Equal( const QuotientRing<INT>& n0 , const QuotientRing<INT>& n1 ) noexcept { return n0.m_n == n1.m_n && n0.m_p_M == n1.m_p_M; } template <typename INT> template <typename T> QuotientRing<INT> QuotientRing<INT>::Power( const QuotientRing<INT>& n , T exponent ) { QuotientRing<INT> answer{ 1 , n.m_p_M }; QuotientRing<INT> power{ n }; while( exponent != 0 ){ if( exponent % 2 == 1 ){ answer *= power; } power *= power; exponent /= 2; } return answer; } template <typename INT> inline bool operator==( const QuotientRing<INT>& n0 , const QuotientRing<INT>& n1 ) noexcept { return QuotientRing<INT>::Equal( n0 , n1 ); } template <typename INT> inline bool operator!=( const QuotientRing<INT>& n0 , const QuotientRing<INT>& n1 ) noexcept { return ! QuotientRing<INT>::Equal( n0 , n1 ); } template <typename INT , typename T> inline QuotientRing<INT> operator+( const QuotientRing<INT>& n0 , const T& n1 ) noexcept { return QuotientRing<INT>( n0 ).operator+=( n1 ); } template <typename INT , typename T> inline QuotientRing<INT> operator-( const QuotientRing<INT>& n0 , const T& n1 ) noexcept { return QuotientRing<INT>( n0 ).operator-=( n1 ); } template <typename INT , typename T> inline QuotientRing<INT> operator*( const QuotientRing<INT>& n0 , const T& n1 ) noexcept { return QuotientRing<INT>( n0 ).operator*=( n1 ); } template <typename INT , typename T> inline QuotientRing<INT> Power( const QuotientRing<INT>& n , T exponent ) { return QuotientRing<INT>::template Power<T>( n , exponent ); } inline void Solve() { CEXPR( uint , bound_N , 1000 ); // 0が3個 CIN_ASSERT( N , 1 , bound_N ); CEXPR( ll , bound_P , 1000000000 ); // 0が9個 CIN_ASSERT( P , N , bound_P ); if( N <= 3 ){ RETURN( N == 1 ? 1 : N == 2 ? 3 % P : 18 % P ); } FACTORIAL_MOD( fact , fact_inv , inv , N , bound_N + 1 , P ); using Q = QuotientRing<ll>; Q f[N + 1] = { 0 }; uint H = sqrt( N ); uint K = N / H; TRPO<Q> g_power[K] = { TRPO<Q>( N + 1 , Q( 1 , &P ) ) }; g_power[1].SetTruncation( N + 1 ); FOREQ( d , 1 , N ){ Q d_copy{ d , &P }; ( g_power[1][d] = f[d] = Power( d_copy , d == 1 ? 0 : d - 2 ) * fact_inv[d] ) *= d_copy; } FOR( k , 2 , K ){ g_power[k] = g_power[k-1] * g_power[1]; } TRPO<Q> g_power2[H + 1] = { g_power[0] , g_power[K - 1] * g_power[1] }; FOREQ( h , 2 , H ){ g_power2[h] = g_power2[h-1] * g_power2[1]; } Q answer{ 0 , &P }; uint k = 0; uint h = 0; uint n_max = N; TRPO<Q> fg_h{ N + 1 }; FOREQ( d , 0 , N ){ FOREQ( n , k , n_max ){ fg_h[n] += f[d] * g_power[k][n]; } if( ++k == K || d == N ){ k = 0; fg_h *= g_power2[h++]; answer += fg_h[N]; fg_h = TRPO<Q>( N + 1 ); n_max -= K; } } answer *= fact[N]; RETURN( answer.Represent() ); } REPEAT_MAIN(1);