結果
問題 | No.2577 Simple Permutation Guess |
ユーザー | 👑 p-adic |
提出日時 | 2023-11-15 20:52:26 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 147 ms / 2,000 ms |
コード長 | 25,412 bytes |
コンパイル時間 | 3,780 ms |
コンパイル使用メモリ | 232,568 KB |
実行使用メモリ | 25,604 KB |
平均クエリ数 | 251.88 |
最終ジャッジ日時 | 2024-09-26 22:27:15 |
合計ジャッジ時間 | 15,928 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
25,196 KB |
testcase_01 | AC | 117 ms
25,052 KB |
testcase_02 | AC | 59 ms
24,940 KB |
testcase_03 | AC | 22 ms
24,812 KB |
testcase_04 | AC | 58 ms
25,196 KB |
testcase_05 | AC | 68 ms
24,940 KB |
testcase_06 | AC | 144 ms
24,812 KB |
testcase_07 | AC | 146 ms
24,556 KB |
testcase_08 | AC | 143 ms
24,812 KB |
testcase_09 | AC | 144 ms
24,812 KB |
testcase_10 | AC | 147 ms
25,196 KB |
testcase_11 | AC | 23 ms
24,812 KB |
testcase_12 | AC | 23 ms
24,812 KB |
testcase_13 | AC | 24 ms
24,940 KB |
testcase_14 | AC | 27 ms
25,196 KB |
testcase_15 | AC | 24 ms
25,324 KB |
testcase_16 | AC | 22 ms
25,196 KB |
testcase_17 | AC | 22 ms
25,184 KB |
testcase_18 | AC | 22 ms
24,812 KB |
testcase_19 | AC | 22 ms
24,812 KB |
testcase_20 | AC | 22 ms
25,196 KB |
testcase_21 | AC | 22 ms
25,196 KB |
testcase_22 | AC | 23 ms
25,460 KB |
testcase_23 | AC | 23 ms
24,952 KB |
testcase_24 | AC | 23 ms
25,220 KB |
testcase_25 | AC | 23 ms
24,824 KB |
testcase_26 | AC | 23 ms
24,836 KB |
testcase_27 | AC | 23 ms
24,964 KB |
testcase_28 | AC | 22 ms
24,836 KB |
testcase_29 | AC | 22 ms
24,580 KB |
testcase_30 | AC | 23 ms
24,964 KB |
testcase_31 | AC | 22 ms
25,196 KB |
testcase_32 | AC | 23 ms
24,952 KB |
testcase_33 | AC | 23 ms
25,064 KB |
testcase_34 | AC | 23 ms
24,940 KB |
testcase_35 | AC | 23 ms
24,812 KB |
testcase_36 | AC | 22 ms
24,940 KB |
testcase_37 | AC | 21 ms
24,836 KB |
testcase_38 | AC | 21 ms
24,836 KB |
testcase_39 | AC | 22 ms
24,836 KB |
testcase_40 | AC | 22 ms
24,964 KB |
testcase_41 | AC | 22 ms
25,476 KB |
testcase_42 | AC | 22 ms
24,836 KB |
testcase_43 | AC | 22 ms
24,836 KB |
testcase_44 | AC | 21 ms
24,964 KB |
testcase_45 | AC | 21 ms
24,836 KB |
testcase_46 | AC | 23 ms
24,836 KB |
testcase_47 | AC | 23 ms
24,836 KB |
testcase_48 | AC | 23 ms
25,220 KB |
testcase_49 | AC | 21 ms
24,964 KB |
testcase_50 | AC | 23 ms
24,836 KB |
testcase_51 | AC | 23 ms
25,604 KB |
testcase_52 | AC | 22 ms
24,964 KB |
testcase_53 | AC | 22 ms
24,836 KB |
testcase_54 | AC | 22 ms
24,836 KB |
testcase_55 | AC | 22 ms
24,836 KB |
testcase_56 | AC | 22 ms
24,964 KB |
testcase_57 | AC | 22 ms
24,836 KB |
testcase_58 | AC | 22 ms
25,220 KB |
testcase_59 | AC | 22 ms
24,964 KB |
testcase_60 | AC | 23 ms
25,220 KB |
testcase_61 | AC | 21 ms
24,836 KB |
testcase_62 | AC | 23 ms
25,220 KB |
testcase_63 | AC | 22 ms
24,836 KB |
testcase_64 | AC | 22 ms
25,220 KB |
testcase_65 | AC | 23 ms
24,964 KB |
testcase_66 | AC | 22 ms
24,836 KB |
testcase_67 | AC | 23 ms
25,220 KB |
testcase_68 | AC | 24 ms
25,604 KB |
testcase_69 | AC | 23 ms
24,964 KB |
testcase_70 | AC | 23 ms
25,220 KB |
testcase_71 | AC | 21 ms
24,580 KB |
testcase_72 | AC | 22 ms
25,220 KB |
testcase_73 | AC | 22 ms
25,452 KB |
testcase_74 | AC | 25 ms
25,196 KB |
testcase_75 | AC | 24 ms
24,940 KB |
testcase_76 | AC | 25 ms
24,812 KB |
testcase_77 | AC | 24 ms
24,940 KB |
testcase_78 | AC | 23 ms
25,196 KB |
testcase_79 | AC | 23 ms
24,556 KB |
testcase_80 | AC | 24 ms
24,812 KB |
testcase_81 | AC | 24 ms
25,196 KB |
testcase_82 | AC | 25 ms
25,196 KB |
testcase_83 | AC | 24 ms
25,196 KB |
testcase_84 | AC | 24 ms
24,812 KB |
testcase_85 | AC | 24 ms
24,812 KB |
testcase_86 | AC | 24 ms
24,812 KB |
testcase_87 | AC | 25 ms
24,796 KB |
testcase_88 | AC | 25 ms
24,812 KB |
testcase_89 | AC | 24 ms
24,812 KB |
testcase_90 | AC | 24 ms
25,196 KB |
testcase_91 | AC | 26 ms
24,812 KB |
testcase_92 | AC | 121 ms
25,196 KB |
testcase_93 | AC | 110 ms
25,196 KB |
testcase_94 | AC | 106 ms
25,196 KB |
testcase_95 | AC | 139 ms
24,940 KB |
testcase_96 | AC | 139 ms
25,196 KB |
testcase_97 | AC | 131 ms
25,196 KB |
testcase_98 | AC | 131 ms
25,196 KB |
testcase_99 | AC | 137 ms
25,184 KB |
testcase_100 | AC | 112 ms
24,812 KB |
testcase_101 | AC | 133 ms
24,812 KB |
evil_1_rnd_1.txt | AC | 258 ms
24,812 KB |
evil_1_rnd_2.txt | AC | 258 ms
25,196 KB |
evil_2_big_1.txt | AC | 321 ms
25,452 KB |
evil_2_big_2.txt | AC | 323 ms
25,196 KB |
evil_2_big_3.txt | AC | 319 ms
24,812 KB |
evil_3_sorted_1.txt | AC | 178 ms
25,208 KB |
evil_4_sorted_rev_1.txt | AC | 159 ms
24,836 KB |
evil_4_sorted_rev_2.txt | AC | 215 ms
25,220 KB |
evil_400_sorted.txt | AC | 295 ms
24,824 KB |
evil_400_sorted_rev.txt | AC | 336 ms
24,836 KB |
ソースコード
#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__ ) << endl #define CERR_A( A , N ) #define COUT_A( A , N ) OUTPUT_ARRAY( cout , A , N ) << endl #define CERR_ITR( A ) #define COUT_ITR( A ) OUTPUT_ITR( cout , A ) << endl #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>; using path = pair<int,ll>; #define ATT __attribute__( ( target( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) ) ) #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 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 , ... ) 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 ); } #define POWER( ANSWER , ARGUMENT , EXPONENT ) \ static_assert( ! is_same<TYPE_OF( ARGUMENT ),int>::value && ! is_same<TYPE_OF( ARGUMENT ),uint>::value ); \ TYPE_OF( ARGUMENT ) ANSWER{ 1 }; \ { \ TYPE_OF( ARGUMENT ) ARGUMENT_FOR_SQUARE_FOR_POWER = ( ARGUMENT ); \ TYPE_OF( EXPONENT ) EXPONENT_FOR_SQUARE_FOR_POWER = ( EXPONENT ); \ while( EXPONENT_FOR_SQUARE_FOR_POWER != 0 ){ \ if( EXPONENT_FOR_SQUARE_FOR_POWER % 2 == 1 ){ \ ANSWER *= ARGUMENT_FOR_SQUARE_FOR_POWER; \ } \ ARGUMENT_FOR_SQUARE_FOR_POWER *= ARGUMENT_FOR_SQUARE_FOR_POWER; \ EXPONENT_FOR_SQUARE_FOR_POWER /= 2; \ } \ } \ #define POWER_MOD( ANSWER , ARGUMENT , EXPONENT , MODULO ) \ ll ANSWER{ 1 }; \ { \ ll ARGUMENT_FOR_SQUARE_FOR_POWER = ( ( ARGUMENT ) % ( MODULO ) ) % ( MODULO ); \ ARGUMENT_FOR_SQUARE_FOR_POWER < 0 ? ARGUMENT_FOR_SQUARE_FOR_POWER += ( MODULO ) : ARGUMENT_FOR_SQUARE_FOR_POWER; \ TYPE_OF( EXPONENT ) EXPONENT_FOR_SQUARE_FOR_POWER = ( EXPONENT ); \ while( EXPONENT_FOR_SQUARE_FOR_POWER != 0 ){ \ if( EXPONENT_FOR_SQUARE_FOR_POWER % 2 == 1 ){ \ ANSWER = ( ANSWER * ARGUMENT_FOR_SQUARE_FOR_POWER ) % ( MODULO ); \ } \ ARGUMENT_FOR_SQUARE_FOR_POWER = ( ARGUMENT_FOR_SQUARE_FOR_POWER * ARGUMENT_FOR_SQUARE_FOR_POWER ) % ( MODULO ); \ EXPONENT_FOR_SQUARE_FOR_POWER /= 2; \ } \ } \ #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 ); \ } \ } \ // 二分探索テンプレート // 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; \ while( VARIABLE_FOR_BINARY_SEARCH_L < VARIABLE_FOR_BINARY_SEARCH_U ){ \ CERR( "二分探索中:" , VARIABLE_FOR_BINARY_SEARCH_L , "<", VARIABLE_FOR_BINARY_SEARCH_U ); \ ll VARIABLE_FOR_EXPRESSION_FOR_BINARY_SEARCH = ( EXPRESSION ); \ ll VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH = VARIABLE_FOR_EXPRESSION_FOR_BINARY_SEARCH - ( TARGET ); \ CERR( "( EXPRESSION =" , VARIABLE_FOR_EXPRESSION_FOR_BINARY_SEARCH , ")" , ( VARIABLE_FOR_EXPRESSION_FOR_BINARY_SEARCH == TARGET ? "==" : VARIABLE_FOR_EXPRESSION_FOR_BINARY_SEARCH < TARGET ? "<" : ">" ) , TARGET ); \ 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( "二分探索失敗:" ); \ ANSWER = MAXIMUM + 1; \ } else { \ CERR( "二分探索終了:" ); \ } \ // 単調増加の時に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 ) \ // t以下の値が存在すればその最大値のiterator、存在しなければend()を返す。 template <typename T> inline typename set<T>::iterator MaximumLeq( set<T>& S , const T& t ) { const auto end = S.end(); if( S.empty() ){ return end; } auto itr = S.upper_bound( t ); return itr == end ? S.find( *( S.rbegin() ) ) : itr == S.begin() ? end : --itr; } // t未満の値が存在すればその最大値のiterator、存在しなければend()を返す。 template <typename T> inline typename set<T>::iterator MaximumLt( set<T>& S , const T& t ) { const auto end = S.end(); if( S.empty() ){ return end; } auto itr = S.lower_bound( t ); return itr == end ? S.find( *( S.rbegin() ) ) : itr == S.begin() ? end : --itr; } // t以上の値が存在すればその最小値のiterator、存在しなければend()を返す。 template <typename T> inline typename set<T>::iterator MinimumGeq( set<T>& S , const T& t ) { return S.lower_bound( t ); } // tより大きい値が存在すればその最小値のiterator、存在しなければend()を返す。 template <typename T> inline typename set<T>::iterator MinimumGt( set<T>& S , const T& t ) { return S.upper_bound( t ); } // データ構造用 template <typename T> inline T Add( const T& t0 , const T& t1 ) { return t0 + t1; } template <typename T> inline T XorAdd( const T& t0 , const T& t1 ){ return t0 ^ t1; } template <typename T> inline T Multiply( const T& t0 , const T& t1 ) { return t0 * t1; } template <typename T> inline const T& Zero() { static const T z = 0; return z; } template <typename T> inline const T& One() { static const T o = 1; return o; }\ template <typename T> inline T AddInv( const T& t ) { return -t; } template <typename T> inline T Id( const T& v ) { return v; } template <typename T> inline T Min( const T& a , const T& b ){ return a < b ? a : b; } template <typename T> inline T Max( const T& a , const T& b ){ return a < b ? b : a; } // グリッド問題用 int H , W , H_minus , W_minus , HW; vector<vector<bool> > non_wall; inline T2<int> EnumHW( const int& v ) { return { v / W , v % W }; } inline int EnumHW_inv( const int& h , const int& w ) { return h * W + w; } const string direction[4] = {"U","R","D","L"}; // (i,j)->(k,h)の方向番号を取得 inline int DirectionNumberOnGrid( const int& i , const int& j , const int& k , const int& h ){return i<k?2:i>k?0:j<h?1:j>h?3:(assert(false),-1);} // v->wの方向番号を取得 inline int DirectionNumberOnGrid( const int& v , const int& w ){auto [i,j]=EnumHW(v);auto [k,h]=EnumHW(w);return DirectionNumberOnGrid(i,j,k,h);} // 方向番号の反転U<->D、R<->L inline int ReverseDirectionNumberOnGrid( const int& n ){assert(0<=n&&n<4);return(n+2)%4;} inline void SetEdgeOnGrid( const string& Si , const int& i , list<int> ( &e )[] , const char& walkable = '.' ){FOR(j,0,W){if(Si[j]==walkable){int v = EnumHW_inv(i,j);if(i>0){e[EnumHW_inv(i-1,j)].push_back(v);}if(i+1<H){e[EnumHW_inv(i+1,j)].push_back(v);}if(j>0){e[EnumHW_inv(i,j-1)].push_back(v);}if(j+1<W){e[EnumHW_inv(i,j+1)].push_back(v);}}}} inline void SetEdgeOnGrid( const string& Si , const int& i , list<path> ( &e )[] , const char& walkable = '.' ){FOR(j,0,W){if(Si[j]==walkable){const int v=EnumHW_inv(i,j);if(i>0){e[EnumHW_inv(i-1,j)].push_back({v,1});}if(i+1<H){e[EnumHW_inv(i+1,j)].push_back({v,1});}if(j>0){e[EnumHW_inv(i,j-1)].push_back({v,1});}if(j+1<W){e[EnumHW_inv(i,j+1)].push_back({v,1});}}}} inline void SetWallOnGrid( const string& Si , const int& i , vector<vector<bool> >& non_wall , const char& walkable = '.' , const char& unwalkable = '#' ){non_wall.push_back(vector<bool>(W));auto& non_wall_i=non_wall[i];FOR(j,0,W){non_wall_i[j]=Si[j]==walkable?true:(assert(Si[j]==unwalkable),false);}} // グラフ用関数 template <typename PATH> list<PATH> E( const int& i ); template <typename PATH> vector<list<PATH> > e; // デバッグ用 #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 // 圧縮用 #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& /* C-x 3 C-x o C-x C-fによるファイル操作用 BIT: c:/Users/user/Documents/Programming/Mathematics/SetTheory/DirectProduct/AffineSpace/BIT/compress.txt BFS: c:/Users/user/Documents/Programming/Mathematics/Geometry/Graph/BreadthFirstSearch/compress.txt DFS on Tree: c:/Users/user/Documents/Programming/Mathematics/Geometry/Graph/DepthFirstSearch/Tree/compress.txt Divisor: c:/Users/user/Documents/Programming/Mathematics/Arithmetic/Prime/Divisor/compress.txt Mod: c:/Users/user/Documents/Programming/Mathematics/Arithmetic/Mod/ConstexprModulo/compress.txt Polynomial c:/Users/user/Documents/Programming/Mathematics/Polynomial/compress.txt */ // VVV ライブラリは以下に挿入する。 // AAA ライブラリは以上に挿入する。 // VVV テンプレート引数用の関数は以下に挿入する。 // H,W,e<PATH>は宣言済み。 template <typename PATH> list<PATH> E( const int& i ) { // list<PATH> answer{}; list<PATH> answer = e<PATH>[i]; // VVV 入力によらない処理は以下に挿入する。 // AAA 入力によらない処理は以上に挿入する。 return answer; } // AAA テンプレート引数用の関数は以上に挿入する。 ll Naive( int N , int M , int K ) { ll answer = N + M + K; return answer; } ll Answer( ll N , ll M , ll K ) { // START_WATCH; ll answer = N + M + K; // // TLに準じる乱択や全探索。デフォルトの猶予は100.0[ms]。 // CEXPR( double , TL , 2000.0 ); // while( CHECK_WATCH( TL ) ){ // } return answer; } inline void Solve() { // // 大きな素数 // CEXPR( ll , P , 998244353 ); // Mod<P>を使う時はコメントアウトしたまま。 // // CEXPR( ll , P , 1000000007 ); // Mod<P>を使う時はP2などに名称変更。 // 数 // DEXPR( int , bound_N , 100000 , 100 ); // 0が5個 // DEXPR( int , bound_N , 1000000000 , 100 ); // 0が9個 // DEXPR( ll , bound_N , 1000000000000000000 , 100 ); // 0が18個 // CEXPR( TYPE_OF( bound_N ) , bound_M , bound_N ); // DEXPR( int , bound_M , 100000 , 100 ); // 0が5個 // DEXPR( int , bound_M , 1000000000 , 100 ); // 0が9個 // DEXPR( ll , bound_M , 1000000000000000000 , 100 ); // 0が18個 CIN( ll , N ); // CIN( ll , M ); // CIN( ll , N , M , K ); // CIN_ASSERT( N , 1 , bound_N ); // ランダムテスト用。上限のデフォルト値は10^5。 // CIN_ASSERT( M , 1 , bound_M ); // ランダムテスト用。上限のデフォルト値は10^5。 int Q[N]{}; if( N < 10 ){ ll fact[N+1] = { 1 }; FOREQ( i , 1 , N ){ fact[i] = fact[i-1] * i; } auto enum_fact = [&]( ll k ){ set<int> unused{}; FOREQ( i , 1 , N ){ unused.insert( i ); } FOR( i , 0 , N ){ int rest[N - i]; { int j = 0; FOR_ITR( unused ){ rest[j++] = *itr; } } unused.erase( Q[i] = rest[k / fact[N - i - 1] ] ); k %= fact[N - i - 1]; } }; auto Ask = [&]( ll k ){ enum_fact( k ); cout << "? "; COUT_A( Q , N ); int QleqP; cin >> QleqP; return QleqP; }; BS3( k , 0 , fact[N] - 1 , Ask( k ) , 1 ); enum_fact( k ); } else { set<int> unused{}; FOREQ( i , 1 , N ){ unused.insert( i ); } FOR( i , 0 , N - 1 ){ int rest[N - i]; { int j = 0; FOR_ITR( unused ){ rest[j++] = *itr; } } auto Ask = [&](int k){ Q[i] = rest[k]; int j = i + 1; FOR_ITR( unused ){ if( *itr != Q[i] ){ Q[j++] = *itr; } } cout << "? "; COUT_A( Q , N ); int QleqP; cin >> QleqP; CERR( "Ask" , i , k , QleqP ); return QleqP; }; BS3( k , 0 , N - i - 1 , Ask( k ) , 1 ); unused.erase( Q[i] = rest[k] ); } Q[N - 1] = *( unused.begin() ); } cout << "! "; COUT_A( Q , N ); // // 文字列 // CIN( string , S ); // CIN( string , T ); // // 配列 // CIN_A( ll , A , N ); // // CIN_A( ll , B , N ); // // vector<ll> A( N ); // // vector<ll> B( N ); // // ll A[bound_N]; // 関数(コンストラクタ)の引数に使う。長さのデフォルト値は10^5。 // // ll B[bound_N]; // 関数(コンストラクタ)の引数に使う。長さのデフォルト値は10^5。 // // FOR( i , 0 , N ){ // // cin >> A[i] >> B[i]; // // } // // 順列 // vector<int> P( N ); // vector<int> P_inv( N ); // FOR( i , 0 , N ){ // cin >> P[i]; // P_inv[--P[i]] = i; // } // // グラフ // e<int>.resize( N ); // // e<path>.resize( N ); // FOR( j , 0 , M ){ // CIN_ASSERT( uj , 1 , N ); // CIN_ASSERT( vj , 1 , N ); // uj--; // vj--; // e<int>[uj].push_back( vj ); // e<int>[vj].push_back( uj ); // // CIN( ll , wj ); // // e<path>[uj].push_back( { vj , wj } ); // // e<path>[vj].push_back( { uj , wj } ); // } // // 座標圧縮や単一クエリタイプなどのための入力格納 // vector<T3<ll> > data( M ); // FOR( j , 0 , M ){ // CIN( ll , x , y , z ); // data[j] = { x , y , z }; // } // // 一般のクエリ // CIN( int , Q ); // // DEXPR( int , bound_Q , 100000 , 100 ); // 基本不要。 // // CIN_ASSERT( Q , 1 , bound_Q ); // 基本不要。 // // vector<T3<int> > query( Q ); // // vector<T2<int> > query( Q ); // FOR( q , 0 , Q ){ // CIN( int , type ); // if( type == 1 ){ // CIN( int , x , y ); // // query[q] = { type , x , y }; // } else if( type == 2 ){ // CIN( int , x , y ); // // query[q] = { type , x , y }; // } else { // CIN( int , x , y ); // // query[q] = { type , x , y }; // } // // CIN( int , x , y ); // // // query[q] = { x , y }; // } // // sort( query , query + Q ); // // FOR( q , 0 , Q ){ // // auto& [x,y] = query[q]; // // // auto& [type,x,y] = query[q]; // // } // // グリッド // DEXPR( int , bound_H , 2000 , 30 ); // // DEXPR( int , bound_H , 100000 , 10 ); // 0が5個 // // CEXPR( int , bound_H , 1000000000 ); // 0が9個 // CEXPR( int , bound_W , bound_H ); // static_assert( ll( bound_H ) * bound_W < ll( 1 ) << 31 ); // CEXPR( int , bound_HW , bound_H * bound_W ); // // CEXPR( int , bound_HW , 100000 ); // 0が5個 // // CEXPR( int , bound_HW , 1000000 ); // 0が6個 // cin >> H >> W; // // SET_ASSERT( H , 1 , bound_H ); // ランダムテスト用。上限のデフォルト値は2*10^3。 // // SET_ASSERT( W , 1 , bound_W ); // ランダムテスト用。上限のデフォルト値は2*10^3。 // H_minus = H - 1; // W_minus = W - 1; // HW = H * W; // // assert( HW <= bound_HW ); // 基本不要。上限のデフォルト値は4*10^6。 // vector<string> S( H ); // FOR( i , 0 , H ){ // cin >> S[i]; // // SetEdgeOnGrid( S[i] , i , e<int> ); // // SetWallOnGrid( S[i] , i , non_wall ); // } // // {h,w}へデコード: EnumHW( v ) // // {h,w}をコード: EnumHW_inv( h , w ); // // (i,j)->(k,h)の方向番号を取得: DirectionNumberOnGrid( i , j , k , h ); // // v->wの方向番号を取得: DirectionNumberOnGrid( v , w ); // // 方向番号の反転U<->D、R<->L: ReverseDirectionNumberOnGrid( n ); // auto answer = Answer( N , M , K ); // RETURN( answer ); // // COUT( answer ); // // COUT_A( A , N ); } 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);