#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; #define TYPE_OF( VAR ) remove_const::type >::type #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #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 QUIT return 0 #define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT #define MAIN main template class TwoByTwoMatrix { public: // private: T m_M00; T m_M01; T m_M10; T m_M11; public: inline TwoByTwoMatrix( const T& M00 , const T& M01 , const T& M10 , const T& M11 ) noexcept; TwoByTwoMatrix& operator=( const TwoByTwoMatrix& mat ) noexcept; inline TwoByTwoMatrix operator*( const TwoByTwoMatrix& mat ) const noexcept; }; template inline TwoByTwoMatrix::TwoByTwoMatrix( const T& M00 , const T& M01 , const T& M10 , const T& M11 ) noexcept : m_M00( M00 ) , m_M01( M01 ) , m_M10( M10 ) , m_M11( M11 ) {} template TwoByTwoMatrix& TwoByTwoMatrix::operator=( const TwoByTwoMatrix& mat ) noexcept { if( &mat != this ){ m_M00 = mat.m_M00; m_M01 = mat.m_M01; m_M10 = mat.m_M10; m_M11 = mat.m_M11; } return *this; } template inline TwoByTwoMatrix TwoByTwoMatrix::operator*( const TwoByTwoMatrix& mat ) const noexcept { return TwoByTwoMatrix( m_M00 * mat.m_M00 + m_M01 * mat.m_M10 , m_M00 * mat.m_M01 + m_M01 * mat.m_M11 , m_M10 * mat.m_M00 + m_M11 * mat.m_M10 , m_M10 * mat.m_M01 + m_M11 * mat.m_M11 ); } int MAIN() { UNTIE; constexpr const int bound = 100; CIN_ASSERT( M11 , - bound , bound ); CIN_ASSERT( M12 , - bound , bound ); CIN_ASSERT( M21 , - bound , bound ); CIN_ASSERT( M22 , - bound , bound ); TwoByTwoMatrix M{ M11 , M12 , M21 , M22 }; TwoByTwoMatrix M3 = M * M * M; cout << M3.m_M00 << " " << M3.m_M01 << "\n"; cout << M3.m_M10 << " " << M3.m_M11 << "\n"; QUIT; }