結果
問題 | No.2197 Same Dish |
ユーザー | 👑 p-adic |
提出日時 | 2022-10-24 12:17:50 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 4,834 bytes |
コンパイル時間 | 1,963 ms |
コンパイル使用メモリ | 204,172 KB |
実行使用メモリ | 8,212 KB |
最終ジャッジ日時 | 2024-06-23 08:45:22 |
合計ジャッジ時間 | 3,093 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
8,064 KB |
testcase_01 | AC | 5 ms
8,192 KB |
testcase_02 | AC | 5 ms
8,064 KB |
testcase_03 | AC | 5 ms
8,064 KB |
testcase_04 | AC | 5 ms
8,192 KB |
testcase_05 | AC | 4 ms
8,192 KB |
testcase_06 | AC | 5 ms
8,192 KB |
testcase_07 | AC | 5 ms
8,192 KB |
testcase_08 | AC | 5 ms
8,192 KB |
testcase_09 | AC | 4 ms
8,192 KB |
testcase_10 | AC | 5 ms
8,192 KB |
testcase_11 | AC | 5 ms
8,192 KB |
testcase_12 | AC | 5 ms
8,064 KB |
testcase_13 | AC | 8 ms
8,192 KB |
testcase_14 | AC | 29 ms
8,192 KB |
testcase_15 | AC | 30 ms
8,064 KB |
testcase_16 | AC | 23 ms
8,064 KB |
testcase_17 | AC | 19 ms
8,192 KB |
testcase_18 | AC | 29 ms
8,192 KB |
testcase_19 | AC | 29 ms
8,192 KB |
testcase_20 | AC | 30 ms
8,192 KB |
testcase_21 | AC | 29 ms
8,064 KB |
testcase_22 | AC | 27 ms
8,212 KB |
ソースコード
// 想定解チェック #include<bits/stdc++.h> using namespace std; using ll = long long; #define TYPE_OF( VAR ) remove_const<remove_reference<decltype( VAR )>::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 FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define QUIT return 0 #define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT #define POWER( ANSWER , VAR , EXPONENT_REF , MODULO ) \ TYPE_OF( VAR ) ANSWER = 1; \ TYPE_OF( VAR ) VARIABLE_FOR_SQUARE_FOR_POWER = VAR; \ while( EXPONENT_REF != 0 ){ \ if( EXPONENT_REF % 2 == 1 ){ \ ANSWER = ( ANSWER * VARIABLE_FOR_SQUARE_FOR_POWER ) % MODULO; \ } \ VARIABLE_FOR_SQUARE_FOR_POWER = ( VARIABLE_FOR_SQUARE_FOR_POWER * VARIABLE_FOR_SQUARE_FOR_POWER ) % MODULO; \ EXPONENT_REF /= 2; \ } \ class Span { public: ll m_Li; ll m_Ri; inline Span( const ll& Li = 0 , const ll& Ri = 0 ) : m_Li( Li ) , m_Ri( Ri ) {} }; class Ord { public: inline Ord() = default; inline bool operator()( const Span& S0 , const Span& S1 ) { return S0.m_Li < S1.m_Li; }; }; // InitialSegmentSumで負の入力を扱うためにuintではなくintをテンプレート引数にする。 template <typename T , int N> class BIT { private: T m_fenwick[N + 1]; public: inline BIT(); inline BIT( const T ( & a )[N] ); inline void Set( const int& i , const T& n ); inline BIT<T,N>& operator+=( const T ( & a )[N] ); void Add( const int& i , const T& n ); T InitialSegmentSum( const int& i_final ); inline T IntervalSum( const int& i_start , const int& i_final ); }; template <typename T , int N> inline BIT<T,N>::BIT() : m_fenwick() {} template <typename T , int N> inline BIT<T,N>::BIT( const T ( & a )[N] ) : m_fenwick() { operator+=( a ); } template <typename T , int N> inline void BIT<T,N>::Set( const int& i , const T& n ) { Add( i , n - IntervalSum( i , i ) ); } template <typename T , int N> inline BIT<T,N>& BIT<T,N>::operator+=( const T ( & a )[N] ) { for( int i = 0 ; i < N ; i++ ){ Add( i , a[i] ); } return *this; } template <typename T , int N> void BIT<T,N>::Add( const int& i , const T& n ) { int j = i + 1; while( j <= N ){ m_fenwick[j] += n; j += ( j & -j ); } return; } template <typename T , int N> T BIT<T,N>::InitialSegmentSum( const int& i_final ) { T sum = 0; int j = i_final + 1; while( j > 0 ){ sum += m_fenwick[j]; j -= j & -j; } return sum; } template <typename T , int N> inline T BIT<T,N>::IntervalSum( const int& i_start , const int& i_final ) { return InitialSegmentSum( i_final ) - InitialSegmentSum( i_start - 1 ); } template <typename T , int N> class HybridBIT : public BIT<T,N> { private: T m_a[N]; public: inline HybridBIT(); inline HybridBIT( const T ( & a )[N] ); inline const T& operator[]( const int& i ) const; inline void Set( const int& i , const T& n ); inline HybridBIT<T,N>& operator+=( const T ( & a )[N] ); inline void Add( const int& i , const T& n ); }; template <typename T , int N> inline HybridBIT<T,N>::HybridBIT() : BIT<T,N>() , m_a() {} template <typename T , int N> inline HybridBIT<T,N>::HybridBIT( const T ( & a )[N] ) : BIT<T,N>() , m_a() { operator+=( a ); } template <typename T , int N> inline const T& HybridBIT<T,N>::operator[]( const int& i ) const { return m_a[i]; } template <typename T , int N> inline void HybridBIT<T,N>::Set( const int& i , const T& n ) { Add( i , n - m_a[i] ); } template <typename T , int N> inline HybridBIT<T,N>& HybridBIT<T,N>::operator+=( const T ( & a )[N] ) { for( int i = 0 ; i < N ; i++ ){ Add( i , a[i] ); } return *this; } template <typename T , int N> inline void HybridBIT<T,N>::Add( const int& i , const T& n ) { m_a[i] += n; BIT<T,N>::Add( i , n ); } int main() { UNTIE; constexpr const int bound_N = 100000; CIN_ASSERT( N , 1 , bound_N ); constexpr const ll bound_K = 1000000000; CIN_ASSERT( K , 1 , bound_K ); constexpr const ll bound_Ri = 200000; Span S[bound_N] = {}; FOR( i , 0 , N ){ Span& Si = S[i]; cin >> Si.m_Li >> Si.m_Ri; assert( 1 <= Si.m_Li && Si.m_Li < Si.m_Ri && Si.m_Ri <= bound_Ri ); } constexpr const ll P = 998244353; int N_copy = N; POWER( total , K , N_copy , P ); sort( S , S + N , Ord() ); ll comp = 1; HybridBIT<ll,bound_Ri + 1> count{}; FOR( i , 0 , N ){ Span& Si = S[i]; comp = ( comp * ( K - count.IntervalSum( Si.m_Li , bound_Ri ) ) ) % P; count.Add( Si.m_Ri - 1 , 1 ); } RETURN( ( total + P - comp ) % P ); }