結果
問題 | No.2308 [Cherry 5th Tune B] もしかして、真? |
ユーザー | 👑 p-adic |
提出日時 | 2023-05-06 17:10:18 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 8,676 bytes |
コンパイル時間 | 1,081 ms |
コンパイル使用メモリ | 83,180 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-18 01:55:45 |
合計ジャッジ時間 | 6,062 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 80 ms
5,248 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 79 ms
5,248 KB |
testcase_20 | WA | - |
testcase_21 | AC | 92 ms
5,248 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 92 ms
5,248 KB |
testcase_25 | AC | 94 ms
5,248 KB |
testcase_26 | AC | 91 ms
5,248 KB |
testcase_27 | AC | 94 ms
5,248 KB |
testcase_28 | AC | 97 ms
5,248 KB |
testcase_29 | AC | 96 ms
5,248 KB |
testcase_30 | AC | 91 ms
5,248 KB |
testcase_31 | AC | 75 ms
5,248 KB |
testcase_32 | AC | 76 ms
5,248 KB |
testcase_33 | WA | - |
testcase_34 | AC | 78 ms
5,248 KB |
testcase_35 | WA | - |
testcase_36 | AC | 78 ms
5,248 KB |
testcase_37 | WA | - |
testcase_38 | WA | - |
ソースコード
#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" // InitialSegmentSumで負の入力を扱うためにuintではなくintをテンプレート引数にする。 // 使用演算: // T& T::operator=( const T& ) // T& T::operator+=( const T& ) // T operator-( const T& , const T& )(ただしIntervalSumを用いない場合は不要) // T operator<( const T& , const T& )(ただしBinarySearchを用いない場合は不要) template <typename T> class BIT { private: int m_N; vector<T> m_fenwick; int m_power; 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; // operator+=の単位元T()より小さくない要素のみを成分に持つ場合のみサポート。 // InitialSegmentSum( i )がt以上となるiが存在する場合にその最小値を2進法で探索。 int BinarySearch( const T& t ) const; }; template <typename T> inline BIT<T>::BIT( const uint& N ) : m_N( N ) , m_fenwick( N + 1 ) , m_power( 1 ) { // 1で初期化 for( int j = 1 ; j <= N ; j++ ){ T& fenwick_j = m_fenwick[j] = 1; int i = j - 1; int i_lim = j - ( j & -j ); while( i != i_lim ){ fenwick_j += m_fenwick[i]; i -= ( i & -i ); } } while( m_power < N ){ m_power <<= 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 ); } template <typename T> inline int BIT<T>::BinarySearch( const T& t ) const { int j = 0; int power = m_power; T sum{}; T sum_next{}; while( power > 0 ){ int j_next = j | power; if( j_next < m_N ){ sum_next += m_fenwick[j_next]; if( sum_next < t ){ sum = sum_next; j = j_next; } else { sum_next = sum; } } power >>= 1; } // InitialSegmentSum( i )がt未満となるiが存在するならばjはその最大値に1を足したものとなり、 // InitialSegmentSum( i )がt未満となるiが存在しないならばj=0となり、 // いずれの場合もjはInitialSegmentSum( i )がt以上となる最小のiと等しい。 return j; } // 入力フォーマットチェック用 // 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 ); } // 「元々命題定数A_i(i < N)があった位置に現時点で置かれている命題定数の添字」を並べた数列の階差数列を管理 BIT<int> Kaiser{ uint( N ) }; FOR( j , 0 , N_minus ){ CIN_ASSERT( Si , 1 , N - j ); // 階差数列の累積和(つまり階差数列を取る前の数列の値)がSi以上となる最小の添字n int n = Kaiser.BinarySearch( Si ); // 階差数列の累積和(つまり階差数列を取る前の数列の値)がSi-1以上となる最小の添字n_prev int n_prev = Kaiser.BinarySearch( --Si ); Kaiser.Add( n , -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; }