結果
問題 | No.2308 [Cherry 5th Tune B] もしかして、真? |
ユーザー | 👑 p-adic |
提出日時 | 2023-05-05 10:55:02 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 419 ms / 2,000 ms |
コード長 | 9,762 bytes |
コンパイル時間 | 1,437 ms |
コンパイル使用メモリ | 84,400 KB |
実行使用メモリ | 5,888 KB |
最終ジャッジ日時 | 2024-12-18 01:55:08 |
合計ジャッジ時間 | 15,975 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 301 ms
5,248 KB |
testcase_02 | AC | 348 ms
5,248 KB |
testcase_03 | AC | 313 ms
5,248 KB |
testcase_04 | AC | 320 ms
5,248 KB |
testcase_05 | AC | 333 ms
5,248 KB |
testcase_06 | AC | 342 ms
5,248 KB |
testcase_07 | AC | 346 ms
5,248 KB |
testcase_08 | AC | 374 ms
5,376 KB |
testcase_09 | AC | 366 ms
5,376 KB |
testcase_10 | AC | 326 ms
5,248 KB |
testcase_11 | AC | 347 ms
5,248 KB |
testcase_12 | AC | 348 ms
5,248 KB |
testcase_13 | AC | 338 ms
5,248 KB |
testcase_14 | AC | 351 ms
5,248 KB |
testcase_15 | AC | 346 ms
5,248 KB |
testcase_16 | AC | 351 ms
5,248 KB |
testcase_17 | AC | 348 ms
5,248 KB |
testcase_18 | AC | 342 ms
5,248 KB |
testcase_19 | AC | 346 ms
5,248 KB |
testcase_20 | AC | 356 ms
5,248 KB |
testcase_21 | AC | 389 ms
5,760 KB |
testcase_22 | AC | 394 ms
5,632 KB |
testcase_23 | AC | 401 ms
5,632 KB |
testcase_24 | AC | 399 ms
5,760 KB |
testcase_25 | AC | 390 ms
5,760 KB |
testcase_26 | AC | 399 ms
5,760 KB |
testcase_27 | AC | 394 ms
5,760 KB |
testcase_28 | AC | 396 ms
5,888 KB |
testcase_29 | AC | 419 ms
5,760 KB |
testcase_30 | AC | 406 ms
5,760 KB |
testcase_31 | AC | 217 ms
5,632 KB |
testcase_32 | AC | 215 ms
5,632 KB |
testcase_33 | AC | 206 ms
5,888 KB |
testcase_34 | AC | 265 ms
5,760 KB |
testcase_35 | AC | 263 ms
5,760 KB |
testcase_36 | AC | 266 ms
5,760 KB |
testcase_37 | AC | 8 ms
5,248 KB |
testcase_38 | AC | 342 ms
5,248 KB |
ソースコード
#pragma GCC optimize ( "O3" ) #pragma GCC optimize( "unroll-loops" ) #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) #include <iostream> #include <stdio.h> #include <stdint.h> #include <cassert> #include <vector> using namespace std; using ll = long long; using uint = unsigned int; #define TYPE_OF( VAR ) remove_const<remove_reference<decltype( VAR )>::type >::type #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define CEXPR( LL , BOUND , VALUE ) constexpr const LL BOUND = VALUE #define CIN( LL , A ) LL A; cin >> A #define ASSERT( A , MIN , MAX ) assert( ( MIN ) <= A && A <= ( MAX ) ) #define CIN_ASSERT( A , MIN , MAX ) CIN( TYPE_OF( MAX ) , A ); ASSERT( A , MIN , MAX ) #define GETLINE( S ) string S; getline( cin , S ) #define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT ## HOW_MANY_TIMES , 0 , HOW_MANY_TIMES ) #define QUIT return 0 #define COUT( ANSWER ) cout << ( ANSWER ) << "\n" #define BS1( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET ) \ ll ANSWER; \ { \ ll VARIABLE_FOR_BINARY_SEARCH_L = MINIMUM; \ ll VARIABLE_FOR_BINARY_SEARCH_U = MAXIMUM; \ ANSWER = ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2; \ 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 ); \ if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH >= 0 ){ \ VARIABLE_FOR_BINARY_SEARCH_U = ANSWER; \ } else { \ VARIABLE_FOR_BINARY_SEARCH_L = ANSWER + 1; \ } \ ANSWER = ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2; \ } \ } \ // InitialSegmentSumで負の入力を扱うためにuintではなくintをテンプレート引数にする。 // 使用演算: // T& T::operator=( const T& ) // T& T::operator+=( const T& ) // T operator-( const T& , const T& )(ただしIntervalSumを用いない場合は不要) template <typename T> class BIT { private: int m_N; vector<T> m_fenwick; public: inline BIT( const uint& N ); inline void Set( const int& i , const T& n ); void Add( const int& i , const T& n ); T InitialSegmentSum( const int& i_final ) const; inline T IntervalSum( const int& i_start , const int& i_final ) const; }; template <typename T> inline BIT<T>::BIT( const uint& N ) : m_N( N ) , m_fenwick( N + 1 ) {} template <typename T> inline void BIT<T>::Set( const int& i , const T& n ) { Add( i , n - IntervalSum( i , i ) ); } template <typename T> void BIT<T>::Add( const int& i , const T& n ) { int j = i + 1; while( j <= m_N ){ m_fenwick[j] += n; j += ( j & -j ); } return; } template <typename T> T BIT<T>::InitialSegmentSum( const int& i_final ) const { T sum = 0; int j = ( i_final < m_N ? i_final : m_N - 1 ) + 1; while( j > 0 ){ sum += m_fenwick[j]; j -= j & -j; } return sum; } template <typename T> inline T BIT<T>::IntervalSum( const int& i_start , const int& i_final ) const { return InitialSegmentSum( i_final ) - InitialSegmentSum( i_start - 1 ); } // 使用演算: // T& T::operator=( const T& )(BITそのものに使用) // T& T::operator+=( const T& ) // T& operator+( const T& , const T& ) // T operator-( const T& ) // T operator-( const T& , const T& ) template <typename T> class IntervalAddBIT { private: // 母関数の微分の負の階差数列((i-1)a_{i-1} - ia_i)の管理 BIT<T> m_bit_0; // 階差数列(a_i - a_{i-1})の管理 BIT<T> m_bit_1; public: inline IntervalAddBIT( const uint& N ); inline T Get( const int& i ) const; inline void Set( const int& i , const T& 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 ) const; inline T IntervalSum( const int& i_start , const int& i_final ) const; }; template <typename T> inline IntervalAddBIT<T>::IntervalAddBIT( const uint& N ) : m_bit_0( N ) , m_bit_1( N ) { FOR( i , 0 , N ){ Set( i , i ); } } template <typename T> inline T IntervalAddBIT<T>::Get( const int& i ) const { return IntervalSum( i , i ); } template <typename T> inline void IntervalAddBIT<T>::Set( const int& i , const T& n ) { Add( i , n - IntervalSum( i , i ) ); } template <typename T> inline void IntervalAddBIT<T>::Add( const int& i , const T& n ) { IntervalAdd( i , i , n ); } template <typename T> inline void IntervalAddBIT<T>::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> inline T IntervalAddBIT<T>::InitialSegmentSum( const int& i_final ) const { return m_bit_0.InitialSegmentSum( i_final ) + i_final * m_bit_1.InitialSegmentSum( i_final ); } template <typename T> inline T IntervalAddBIT<T>::IntervalSum( const int& i_start , const int& i_final ) const { return InitialSegmentSum( i_final ) - InitialSegmentSum( i_start - 1 ); } // 入力フォーマットチェック用 // 1行中の変数の個数を確認 #define GETLINE_COUNT( S , VARIABLE_NUMBER ) GETLINE( S ); int VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S = 0; int VARIABLE_FOR_SIZE_FOR_GETLINE_FOR_ ## S = S.size(); { int size = S.size(); int count = 0; for( int i = 0 ; i < size ; i++ ){ if( S.substr( i , 1 ) == " " ){ count++; } } assert( count + 1 == VARIABLE_NUMBER ); } // 余計な入力の有無を確認 #define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; cin >> VARIABLE_FOR_CHECK_REDUNDANT_INPUT; assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin ) // #define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; getline( cin , VARIABLE_FOR_CHECK_REDUNDANT_INPUT ); assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin ) // |N| <= BOUNDを満たすNをSから構築 #define STOI( S , N , BOUND ) TYPE_OF( BOUND ) N = 0; { bool VARIABLE_FOR_POSITIVITY_FOR_GETLINE = true; assert( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_GETLINE_FOR_ ## S ); if( S.substr( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S , 1 ) == "-" ){ VARIABLE_FOR_POSITIVITY_FOR_GETLINE = false; VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S ++; assert( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_GETLINE_FOR_ ## S ); } assert( S.substr( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S , 1 ) != " " ); string VARIABLE_FOR_LETTER_FOR_GETLINE{}; int VARIABLE_FOR_DIGIT_FOR_GETLINE{}; while( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_GETLINE_FOR_ ## S ? ( VARIABLE_FOR_LETTER_FOR_GETLINE = S.substr( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S , 1 ) ) != " " : false ){ VARIABLE_FOR_DIGIT_FOR_GETLINE = stoi( VARIABLE_FOR_LETTER_FOR_GETLINE ); assert( N < BOUND / 10 ? true : N == BOUND / 10 && VARIABLE_FOR_DIGIT_FOR_GETLINE <= BOUND % 10 ); N = N * 10 + VARIABLE_FOR_DIGIT_FOR_GETLINE; VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S ++; } if( ! VARIABLE_FOR_POSITIVITY_FOR_GETLINE ){ N *= -1; } if( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_GETLINE_FOR_ ## S ){ VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S ++; } } // SをSEPARATORで区切りTを構築 #define SEPARATE( S , T , SEPARATOR ) string T{}; { assert( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_GETLINE_FOR_ ## S ); int VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S_prev = VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S; assert( S.substr( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S , 1 ) != SEPARATOR ); string VARIABLE_FOR_LETTER_FOR_GETLINE{}; while( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_GETLINE_FOR_ ## S ? ( VARIABLE_FOR_LETTER_FOR_GETLINE = S.substr( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S , 1 ) ) != SEPARATOR : false ){ VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S ++; } T = S.substr( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S_prev , VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S - VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S_prev ); if( VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S < VARIABLE_FOR_SIZE_FOR_GETLINE_FOR_ ## S ){ VARIABLE_FOR_INDEX_FOR_GETLINE_FOR_ ## S ++; } } int main() { UNTIE; CEXPR( int , bound_T , 100000 ); CIN_ASSERT( T , 1 , bound_T ); CEXPR( int , bound_N_sum , 200000 ); int N_rest = bound_N_sum; string True = "True"; string False = "False"; CEXPR( int , op_length , 4 ); string op[op_length] = { "and" , "or" , "xor" , "imp" }; bool X[bound_N_sum]; int Y[bound_N_sum]; REPEAT( T ){ CIN_ASSERT( N , 2 , N_rest ); N_rest -= N; FOR( i , 0 , N ){ CIN( string , Xi ); X[i] = Xi == True ? true : ( assert( Xi == False ) , false ); } int N_minus = N - 1; FOR( i , 0 , N_minus ){ CIN( string , Yi ); bool found = false; FOR( j , 0 , op_length ){ if( Yi == op[j] ){ Y[i] = j; found = true; break; } } assert( found ); } IntervalAddBIT<int> left_endpoint{ uint( N ) }; FOR( j , 0 , N_minus ){ CIN_ASSERT( Si , 1 , N - j ); BS1( n , 0 , N_minus , left_endpoint.Get( n ) , Si ); Si--; BS1( n_prev , 0 , n - 1 , left_endpoint.Get( n_prev ) , Si ); left_endpoint.IntervalAdd( n , N_minus , -1 ); int& Yn = Y[n - 1]; X[n_prev] = Yn == 0 ? ( X[n_prev] && X[n] ) : Yn == 1 ? ( X[n_prev] || X[n] ) : Yn == 2 ? ( X[n_prev] != X[n] ) : ( ( !X[n_prev] ) || X[n] ); } COUT( X[0] ? True : False ); } CHECK_REDUNDANT_INPUT; QUIT; }