// 誤解法(O(QN)愚直解)チェック #pragma GCC optimize ( "O3" ) #pragma GCC optimize( "unroll-loops" ) #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) #include #include #include #include using namespace std; using ll = long long; #define MAIN main #define TYPE_OF( VAR ) remove_const::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 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 REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT ## HOW_MANY_TIMES , 0 , HOW_MANY_TIMES ) #define QUIT return 0 int MAIN() { UNTIE; CEXPR( int , bound_N , 100000 ); CIN_ASSERT( N , 1 , bound_N ); CEXPR( ll , bound_B , 1000000000 ); CIN_ASSERT( B , 1 , bound_B ); CEXPR( int , bound_Q , 100000 ); CIN_ASSERT( Q , 1 , bound_Q ); static int X[bound_N] = {}; static ll Y[bound_N] = {}; static ll Z[bound_N] = {}; FOR( i , 0 , N ){ Z[i] = Y[i] = X[i] = 1; } REPEAT( Q ){ CIN_ASSERT( L , 1 , N ); CIN_ASSERT( M , L , N ); CIN_ASSERT( R , M , N ); L--; M--; R--; FOREQ( i , L , R ){ ll& Zi = Z[i]; ( ( Y[i] *= 3 ) += ( ( ( ++X[i] ) %= B ) * Zi ) << 1 ) %= B; ( Zi *= 3 ) %= B; } cout << X[M] << " " << Y[M] << " " << Z[M] << "\n"; } QUIT; }