結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー 👑 p-adicp-adic
提出日時 2023-05-05 11:02:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 490 ms / 2,000 ms
コード長 9,986 bytes
コンパイル時間 1,428 ms
コンパイル使用メモリ 95,076 KB
実行使用メモリ 10,980 KB
最終ジャッジ日時 2024-06-02 00:27:33
合計ジャッジ時間 20,266 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 390 ms
5,376 KB
testcase_02 AC 446 ms
6,980 KB
testcase_03 AC 394 ms
6,740 KB
testcase_04 AC 424 ms
6,812 KB
testcase_05 AC 427 ms
7,512 KB
testcase_06 AC 396 ms
7,852 KB
testcase_07 AC 396 ms
7,708 KB
testcase_08 AC 426 ms
8,548 KB
testcase_09 AC 440 ms
9,080 KB
testcase_10 AC 409 ms
6,884 KB
testcase_11 AC 417 ms
6,880 KB
testcase_12 AC 447 ms
7,060 KB
testcase_13 AC 436 ms
7,152 KB
testcase_14 AC 425 ms
7,144 KB
testcase_15 AC 413 ms
7,028 KB
testcase_16 AC 396 ms
7,156 KB
testcase_17 AC 397 ms
6,748 KB
testcase_18 AC 410 ms
6,740 KB
testcase_19 AC 411 ms
6,944 KB
testcase_20 AC 397 ms
6,740 KB
testcase_21 AC 439 ms
10,980 KB
testcase_22 AC 490 ms
9,956 KB
testcase_23 AC 435 ms
9,956 KB
testcase_24 AC 469 ms
9,956 KB
testcase_25 AC 441 ms
10,976 KB
testcase_26 AC 441 ms
10,080 KB
testcase_27 AC 447 ms
10,848 KB
testcase_28 AC 457 ms
10,980 KB
testcase_29 AC 454 ms
10,852 KB
testcase_30 AC 437 ms
9,952 KB
testcase_31 AC 250 ms
8,544 KB
testcase_32 AC 251 ms
8,548 KB
testcase_33 AC 251 ms
8,544 KB
testcase_34 AC 318 ms
9,704 KB
testcase_35 AC 325 ms
9,696 KB
testcase_36 AC 318 ms
9,572 KB
testcase_37 AC 15 ms
5,376 KB
testcase_38 AC 402 ms
7,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 入力フォーマットチェック
#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 );
  GETLINE_COUNT( T_str , 1 );
  STOI( T_str , T , 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 ){
    GETLINE_COUNT( N_str , 1 );
    STOI( N_str , N , N_rest );
    N_rest -= N;
    GETLINE_COUNT( X_str , N );
    FOR( i , 0 , N ){
      SEPARATE( X_str , Xi , " " );
      X[i] = Xi == True ? true : ( assert( Xi == False ) , false );
    }
    int N_minus = N - 1;
    GETLINE_COUNT( Y_str , N_minus );
    FOR( i , 0 , N_minus ){
      SEPARATE( Y_str , 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 ) };
    GETLINE_COUNT( S_str , N_minus );
    FOR( j , 0 , N_minus ){
      STOI( S_str , Si , 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;
}
0