結果
問題 | No.2421 entersys? |
ユーザー | 👑 p-adic |
提出日時 | 2023-08-15 18:48:32 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,043 ms / 3,000 ms |
コード長 | 24,591 bytes |
コンパイル時間 | 4,678 ms |
コンパイル使用メモリ | 264,476 KB |
実行使用メモリ | 76,672 KB |
最終ジャッジ日時 | 2024-05-03 05:38:23 |
合計ジャッジ時間 | 36,508 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 13 ms
18,176 KB |
testcase_01 | AC | 16 ms
18,432 KB |
testcase_02 | AC | 16 ms
18,688 KB |
testcase_03 | AC | 14 ms
18,304 KB |
testcase_04 | AC | 14 ms
18,432 KB |
testcase_05 | AC | 15 ms
18,560 KB |
testcase_06 | AC | 16 ms
18,560 KB |
testcase_07 | AC | 16 ms
18,816 KB |
testcase_08 | AC | 17 ms
18,816 KB |
testcase_09 | AC | 18 ms
18,944 KB |
testcase_10 | AC | 17 ms
18,688 KB |
testcase_11 | AC | 1,536 ms
58,880 KB |
testcase_12 | AC | 1,495 ms
59,008 KB |
testcase_13 | AC | 1,570 ms
58,880 KB |
testcase_14 | AC | 1,516 ms
58,880 KB |
testcase_15 | AC | 1,555 ms
58,880 KB |
testcase_16 | AC | 1,661 ms
65,408 KB |
testcase_17 | AC | 1,588 ms
65,408 KB |
testcase_18 | AC | 1,546 ms
65,536 KB |
testcase_19 | AC | 1,584 ms
65,536 KB |
testcase_20 | AC | 1,547 ms
65,536 KB |
testcase_21 | AC | 1,462 ms
64,256 KB |
testcase_22 | AC | 1,139 ms
54,528 KB |
testcase_23 | AC | 2,013 ms
76,672 KB |
testcase_24 | AC | 2,026 ms
76,544 KB |
testcase_25 | AC | 2,043 ms
76,544 KB |
testcase_26 | AC | 963 ms
48,384 KB |
testcase_27 | AC | 960 ms
48,512 KB |
testcase_28 | AC | 1,032 ms
48,512 KB |
ソースコード
#ifdef DEBUG #define _GLIBCXX_DEBUG #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ); signal( SIGABRT , &AlertAbort ) #define DEXPR( LL , BOUND , VALUE , DEBUG_VALUE ) CEXPR( LL , BOUND , DEBUG_VALUE ) #define CERR( MESSAGE ) cerr << MESSAGE << endl; #define COUT( ANSWER ) cout << ANSWER << endl #define ASSERT( A , MIN , MAX ) CERR( "ASSERTチェック: " << ( MIN ) << ( ( MIN ) <= A ? "<=" : ">" ) << A << ( A <= ( MAX ) ? "<=" : ">" ) << ( MAX ) ); assert( ( MIN ) <= A && A <= ( MAX ) ) #define LIBRARY_SEARCH bool searched_library = false; LibrarySearch( searched_library ); if( searched_library ){ QUIT; }; #define START_WATCH( PROCESS_NAME ) StartWatch( PROCESS_NAME ) #define STOP_WATCH( HOW_MANY_TIMES ) StopWatch( HOW_MANY_TIMES ) #else #pragma GCC optimize ( "O3" ) #pragma GCC optimize( "unroll-loops" ) #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define DEXPR( LL , BOUND , VALUE , DEBUG_VALUE ) CEXPR( LL , BOUND , VALUE ) #define CERR( MESSAGE ) #define COUT( ANSWER ) cout << ANSWER << "\n" #define ASSERT( A , MIN , MAX ) assert( ( MIN ) <= A && A <= ( MAX ) ) #define LIBRARY_SEARCH #define START_WATCH( PROCESS_NAME ) #define STOP_WATCH( HOW_MANY_TIMES ) #endif // #define RANDOM_TEST #include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; #define ATT __attribute__( ( target( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) ) ) #define TYPE_OF( VAR ) decay_t<decltype( VAR )> #define CEXPR( LL , BOUND , VALUE ) constexpr LL BOUND = VALUE #define CIN( LL , A ) LL A; cin >> A #define CIN_ASSERT( A , MIN , MAX ) TYPE_OF( MAX ) A; SET_ASSERT( A , MIN , MAX ) #define GETLINE( A ) string A; getline( cin , A ) #define GETLINE_SEPARATE( A , SEPARATOR ) string A; getline( cin , A , SEPARATOR ) #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 FOREQINV( VAR , INITIAL , FINAL ) for( TYPE_OF( INITIAL ) VAR = INITIAL ; VAR >= FINAL ; VAR -- ) #define AUTO_ITR( ARRAY ) auto itr_ ## ARRAY = ARRAY .begin() , end_ ## ARRAY = ARRAY .end() #define FOR_ITR( ARRAY ) for( AUTO_ITR( ARRAY ) , itr = itr_ ## ARRAY ; itr_ ## ARRAY != end_ ## ARRAY ; itr_ ## ARRAY ++ , itr++ ) #define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT_ ## HOW_MANY_TIMES , 0 , HOW_MANY_TIMES ) #define QUIT return 0 #define SET_PRECISION( DECIMAL_DIGITS ) cout << fixed << setprecision( DECIMAL_DIGITS ) #ifdef DEBUG inline void AlertAbort( int n ) { CERR( "abort関数が呼ばれました。assertマクロのメッセージが出力されていない場合はオーバーフローの有無を確認をしてください。" ); } void StartWatch( const string& process_name = "nothing" ); void StopWatch( const int& how_many_times = 1 ); #endif #if defined( DEBUG ) && defined( RANDOM_TEST ) inline CEXPR( int , bound_random_test_num , 1000 ); #define START_MAIN FOR( random_test_num , 0 , bound_random_test_num ){ CERR( "(" << random_test_num << ")" ); ll GetRand( const ll& Rand_min , const ll& Rand_max ); #define SET_ASSERT( A , MIN , MAX ) CERR( #A << " = " << ( A = GetRand( MIN , MAX ) ) ) #define RETURN( ANSWER ) if( ( ANSWER ) == guchoku ){ CERR( ( ANSWER ) << " == " << guchoku ); continue; } else { CERR( ( ANSWER ) << " != " << guchoku ); QUIT; } #define FINISH_MAIN CERR( "" ); } #else #define START_MAIN #define SET_ASSERT( A , MIN , MAX ) cin >> A; ASSERT( A , MIN , MAX ) #define RETURN( ANSWER ) COUT( ( ANSWER ) ); QUIT #define FINISH_MAIN #endif template <typename T> inline T Absolute( const T& a ){ return a > 0 ? a : -a; } template <typename T> inline T Residue( const T& a , const T& p ){ return a >= 0 ? a % p : p - 1 - ( ( - ( a + 1 ) ) % p ); } #define POWER( ANSWER , ARGUMENT , EXPONENT ) \ static_assert( ! is_same<TYPE_OF( ARGUMENT ),int>::value && ! is_same<TYPE_OF( ARGUMENT ),uint>::value ); \ TYPE_OF( ARGUMENT ) ANSWER{ 1 }; \ { \ TYPE_OF( ARGUMENT ) ARGUMENT_FOR_SQUARE_FOR_POWER = ( ARGUMENT ); \ TYPE_OF( EXPONENT ) EXPONENT_FOR_SQUARE_FOR_POWER = ( EXPONENT ); \ while( EXPONENT_FOR_SQUARE_FOR_POWER != 0 ){ \ if( EXPONENT_FOR_SQUARE_FOR_POWER % 2 == 1 ){ \ ANSWER *= ARGUMENT_FOR_SQUARE_FOR_POWER; \ } \ ARGUMENT_FOR_SQUARE_FOR_POWER *= ARGUMENT_FOR_SQUARE_FOR_POWER; \ EXPONENT_FOR_SQUARE_FOR_POWER /= 2; \ } \ } \ #define POWER_MOD( ANSWER , ARGUMENT , EXPONENT , MODULO ) \ ll ANSWER{ 1 }; \ { \ ll ARGUMENT_FOR_SQUARE_FOR_POWER = ( ( MODULO ) + ( ( ARGUMENT ) % ( MODULO ) ) ) % ( MODULO ); \ TYPE_OF( EXPONENT ) EXPONENT_FOR_SQUARE_FOR_POWER = ( EXPONENT ); \ while( EXPONENT_FOR_SQUARE_FOR_POWER != 0 ){ \ if( EXPONENT_FOR_SQUARE_FOR_POWER % 2 == 1 ){ \ ANSWER = ( ANSWER * ARGUMENT_FOR_SQUARE_FOR_POWER ) % ( MODULO ); \ } \ ARGUMENT_FOR_SQUARE_FOR_POWER = ( ARGUMENT_FOR_SQUARE_FOR_POWER * ARGUMENT_FOR_SQUARE_FOR_POWER ) % ( MODULO ); \ EXPONENT_FOR_SQUARE_FOR_POWER /= 2; \ } \ } \ #define FACTORIAL_MOD( ANSWER , ANSWER_INV , INVERSE , MAX_INDEX , CONSTEXPR_LENGTH , MODULO ) \ static ll ANSWER[CONSTEXPR_LENGTH]; \ static ll ANSWER_INV[CONSTEXPR_LENGTH]; \ static ll INVERSE[CONSTEXPR_LENGTH]; \ { \ ll VARIABLE_FOR_PRODUCT_FOR_FACTORIAL = 1; \ ANSWER[0] = VARIABLE_FOR_PRODUCT_FOR_FACTORIAL; \ FOREQ( i , 1 , MAX_INDEX ){ \ ANSWER[i] = ( VARIABLE_FOR_PRODUCT_FOR_FACTORIAL *= i ) %= ( MODULO ); \ } \ ANSWER_INV[0] = ANSWER_INV[1] = INVERSE[1] = VARIABLE_FOR_PRODUCT_FOR_FACTORIAL = 1; \ FOREQ( i , 2 , MAX_INDEX ){ \ ANSWER_INV[i] = ( VARIABLE_FOR_PRODUCT_FOR_FACTORIAL *= INVERSE[i] = ( MODULO ) - ( ( ( ( MODULO ) / i ) * INVERSE[ ( MODULO ) % i ] ) % ( MODULO ) ) ) %= ( MODULO ); \ } \ } \ // 二分探索テンプレート // EXPRESSIONがANSWERの広義単調関数の時、EXPRESSION >= TARGETの整数解を格納。 #define BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , DESIRED_INEQUALITY , TARGET , INEQUALITY_FOR_CHECK , UPDATE_U , UPDATE_L , UPDATE_ANSWER ) \ static_assert( ! is_same<TYPE_OF( TARGET ),uint>::value && ! is_same<TYPE_OF( TARGET ),ull>::value ); \ ll ANSWER = MINIMUM; \ if( MINIMUM <= MAXIMUM ){ \ 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 ); \ CERR( "二分探索中: " << VARIABLE_FOR_BINARY_SEARCH_L << "<=" << ANSWER << "<=" << VARIABLE_FOR_BINARY_SEARCH_U << ":" << EXPRESSION << "-" << TARGET << "=" << VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH ); \ if( VARIABLE_FOR_DIFFERENCE_FOR_BINARY_SEARCH INEQUALITY_FOR_CHECK 0 ){ \ VARIABLE_FOR_BINARY_SEARCH_U = UPDATE_U; \ } else { \ VARIABLE_FOR_BINARY_SEARCH_L = UPDATE_L; \ } \ ANSWER = UPDATE_ANSWER; \ } \ CERR( "二分探索終了: " << VARIABLE_FOR_BINARY_SEARCH_L << "<=" << ANSWER << "<=" << VARIABLE_FOR_BINARY_SEARCH_U << ":" << EXPRESSION << ( EXPRESSION > TARGET ? ">" : EXPRESSION < TARGET ? "<" : "=" ) << TARGET ); \ CERR( ( EXPRESSION DESIRED_INEQUALITY TARGET ? "二分探索成功" : "二分探索失敗" ) ); \ assert( EXPRESSION DESIRED_INEQUALITY TARGET ); \ } else { \ CERR( "二分探索失敗: " << MINIMUM << ">" << MAXIMUM ); \ assert( MINIMUM <= MAXIMUM ); \ } \ // 単調増加の時にEXPRESSION >= TARGETの最小解を格納。 #define BS1( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET ) \ BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , >= , TARGET , >= , ANSWER , ANSWER + 1 , ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \ // 単調増加の時にEXPRESSION <= TARGETの最大解を格納。 #define BS2( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET ) \ BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , <= , TARGET , > , ANSWER - 1 , ANSWER , ( VARIABLE_FOR_BINARY_SEARCH_L + 1 + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \ // 単調減少の時にEXPRESSION >= TARGETの最大解を格納。 #define BS3( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET ) \ BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , >= , TARGET , < , ANSWER - 1 , ANSWER , ( VARIABLE_FOR_BINARY_SEARCH_L + 1 + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \ // 単調減少の時にEXPRESSION <= TARGETの最小解を格納。 #define BS4( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , TARGET ) \ BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , <= , TARGET , <= , ANSWER , ANSWER + 1 , ( VARIABLE_FOR_BINARY_SEARCH_L + VARIABLE_FOR_BINARY_SEARCH_U ) / 2 ) \ template <typename T> class CoordinateCompress { private: vector<T> m_a; map<T,int> m_enum; bool m_compressed; int m_size; public: inline CoordinateCompress(); template <typename U , int length_max> inline CoordinateCompress( const U ( &a )[length_max] , const int& length ); template <typename U> inline CoordinateCompress( const vector<U>& a ); inline void Insert( const T& t ); template <typename U , int length_max> inline void Insert( const U ( &a )[length_max] , const int& length ); template <typename U> inline void Insert( const vector<U>& a ); inline const T& GetSmallest( const int& i = 0 ); inline const T& GetLargest( const int& i = 0 ); inline int GetOrder( const T& t ); inline const int& size(); inline typename map<T,int>::iterator begin(); inline typename map<T,int>::iterator end(); private: inline void Compress(); }; template <typename T> inline CoordinateCompress<T>::CoordinateCompress() : m_a() , m_enum() , m_compressed() , m_size() {} template <typename T> template <typename U , int length_max> inline CoordinateCompress<T>::CoordinateCompress( const U ( &a )[length_max] , const int& length ) : CoordinateCompress() { Insert( a , length ); } template <typename T> template <typename U> inline CoordinateCompress<T>::CoordinateCompress( const vector<U>& a ) : CoordinateCompress() { Insert( a ); } template <typename T> inline void CoordinateCompress<T>::Insert( const T& t ) { m_enum[t]; m_size = m_enum.size(); m_compressed = false; } template <typename T> template <typename U , int length_max> inline void CoordinateCompress<T>::Insert( const U ( &a )[length_max] , const int& length ) { assert( length <= length_max ); if( length > 0 ){ for( int i = 0 ; i < length ; i++ ){ m_enum[ a[i] ]; } m_size = m_enum.size(); m_compressed = false; } } template <typename T> template <typename U> inline void CoordinateCompress<T>::Insert( const vector<U>& a ) { const int length = a.size(); if( length > 0 ){ for( int i = 0 ; i < length ; i++ ){ m_enum[ a[i] ]; } m_size = m_enum.size(); m_compressed = false; } } template <typename T> inline const T& CoordinateCompress<T>::GetSmallest( const int& i ) { if( ! m_compressed ){ Compress(); } assert( i < m_size ); return m_a[i]; } template <typename T> inline const T& CoordinateCompress<T>::GetLargest( const int& i ) { if( ! m_compressed ){ Compress(); } assert( i < m_size ); return m_a[m_size - i - 1]; } template <typename T> inline int CoordinateCompress<T>::GetOrder( const T& t ) { if( ! m_compressed ){ Compress(); } return m_enum.count( t ) == 1 ? m_enum[t] : -1; } template <typename T> inline const int& CoordinateCompress<T>::size() { return m_size; } template <typename T> inline typename map<T,int>::iterator CoordinateCompress<T>::begin() { return m_enum.begin(); } template <typename T> inline typename map<T,int>::iterator CoordinateCompress<T>::end() { return m_enum.end(); } template <typename T> inline void CoordinateCompress<T>::Compress() { m_a.resize( m_size ); m_size = 0; for( auto itr = m_enum.begin() , end = m_enum.end() ; itr != end ; itr++ ){ m_a[itr->second = m_size++] = itr->first; } m_compressed = true; } // 配列の各要素がint型の範疇でも総和がそうでない場合はTをint型にすると正しく動作しないことに注意。 // 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 , int N> class BIT { private: T m_fenwick[N + 1]; public: inline BIT(); BIT( const T ( & a )[N] ); // const参照でないことに注意。 inline T Get( const int& i ) const; inline void Set( const int& i , const T& n ); inline void Set( const T ( & a )[N] ); inline BIT<T,N>& operator+=( const T ( & a )[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 )がn以上となるiが存在する場合にその最小値を2進法で探索。 int BinarySearch( const T& n ) const; // IntervalSum( i_start , i )がt以上となるi_start以上のiが存在する場合にその最小値を2進法で探索。 inline int BinarySearch( const int& i_start , const T& n ) const; }; template <typename T , int N> inline BIT<T,N>::BIT() : m_fenwick() {} template <typename T , int N> BIT<T,N>::BIT( const T ( & a )[N] ) : m_fenwick() { for( int j = 1 ; j <= N ; j++ ){ T& fenwick_j = m_fenwick[j]; int i = j - 1; fenwick_j = a[i]; int i_lim = j - ( j & -j ); while( i != i_lim ){ fenwick_j += m_fenwick[i]; i -= ( i & -i ); } } } template <typename T , int N> inline T BIT<T,N>::Get( const int& i ) const { return IntervalSum( i , i ); } 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 void BIT<T,N>::Set( const T ( & a )[N] ) { BIT<T,N> a_copy{ a }; swap( m_fenwick , a_copy.m_fenwick ); } 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 ) const { T sum = 0; int j = ( i_final < N ? i_final : N - 1 ) + 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 ) 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 , int N> class IntervalAddBIT { private: // 母関数の微分の負の階差数列((i-1)a_{i-1} - ia_i)の管理 BIT<T,N> m_bit_0; // 階差数列(a_i - a_{i-1})の管理 BIT<T,N> m_bit_1; public: inline IntervalAddBIT(); inline IntervalAddBIT( const T ( &a )[N] ); // const参照でないことに注意。 inline T Get( const int& i ) const; inline void Set( const int& i , const T& n ); inline void Set( const T ( &a )[N] ); inline IntervalAddBIT<T,N>& operator+=( const T ( & a )[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 , int N> inline IntervalAddBIT<T,N>::IntervalAddBIT() : m_bit_0() , m_bit_1() {} template <typename T , int N> inline IntervalAddBIT<T,N>::IntervalAddBIT( const T ( &a )[N] ) : m_bit_0() , m_bit_1() { operator+=( a ); } template <typename T , int N> inline T IntervalAddBIT<T,N>::Get( const int& i ) const { return IntervalSum( i , i ); } template <typename T , int N> inline void IntervalAddBIT<T,N>::Set( const int& i , const T& n ) { Add( i , n - IntervalSum( i , i ) ); } template <typename T , int N> inline void IntervalAddBIT<T,N>::Set( const T ( &a )[N] ) { IntervalAddBIT<T,N> a_copy{ a }; swap( m_bit_0 , a_copy.m_bit_0 ); swap( m_bit_1 , a_copy.m_bit_1 ); } template <typename T , int N> inline IntervalAddBIT<T,N>& IntervalAddBIT<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 IntervalAddBIT<T,N>::Add( const int& i , const T& n ) { IntervalAdd( i , i , n ); } template <typename T , int N> inline void IntervalAddBIT<T,N>::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 , int N> inline T IntervalAddBIT<T,N>::InitialSegmentSum( const int& i_final ) const { return m_bit_0.InitialSegmentSum( i_final ) + i_final * m_bit_1.InitialSegmentSum( i_final ); } template <typename T , int N> inline T IntervalAddBIT<T,N>::IntervalSum( const int& i_start , const int& i_final ) const { return InitialSegmentSum( i_final ) - InitialSegmentSum( i_start - 1 ); } // inline CEXPR( int , bound_N , 10 ); inline DEXPR( int , bound_N , 100000 , 100 ); // 0が5個 // inline CEXPR( int , bound_N , 1000000000 ); // 0が9個 // inline CEXPR( ll , bound_N , 1000000000000000000 ); // 0が18個 TYPE_OF( bound_N ) N; // // inline CEXPR( TYPE_OF( bound_N ) , bound_M , bound_N ); // // inline CEXPR( int , bound_M , 10 ); // inline DEXPR( int , bound_M , 100000 , 100 ); // 0が5個 // // inline CEXPR( int , bound_M , 1000000000 ); // 0が9個 // // inline CEXPR( ll , bound_M , 1000000000000000000 ); // 0が18個 // TYPE_OF( bound_M ) M; // inline DEXPR( int , bound_H , 1000 , 10 ); // // inline DEXPR( int , bound_H , 100000 , 10 ); // 0が5個 // // inline CEXPR( int , bound_H , 1000000000 ); // 0が9個 // inline CEXPR( int , bound_W , bound_H ); // #if bound_H < ( 1 << 16 ) // inline CEXPR( int , bound_HW , bound_H * bound_W ); // #else // inline CEXPR( ll , bound_HW , ll( bound_H ) * bound_W ); // #endif // // CEXPR( int , bound_HW , 100000 ); // 0が5個 // // CEXPR( int , bound_HW , 1000000000 ); // 0が5個 // int H , W; // inline int EnumHW( const int& h , const int& w ) { return h * W + w; } // inline pair<int,int> EnumHW_inv( const int& v ) { return { v / W , v % W }; } // inline void SetEdgeOnGrid( const string& Si , const int& i , list<int> ( &e )[bound_HW] , const char& walkable = '.' ){FOR(j,0,W){if(Si[j]==walkable){int v = EnumHW(i,j);if(i>0){e[EnumHW(i-1,j)].push_back(v);}if(i+1<H){e[EnumHW(i+1,j)].push_back(v);}if(j>0){e[EnumHW(i,j-1)].push_back(v);}if(j+1<W){e[EnumHW(i,j+1)].push_back(v);}}}} // const string direction[4] = {"U","R","D","L"}; // inline int DirectionNumberOnGrid( const int& i , const int& j , const int& k , const int& h ){return i<k?2:i>k?0:j<h?1:j>h?3:(assert(false),-1);} // inline int DirectionNumberOnGrid( const int& v , const int& w ){auto [i,j]=EnumHW_inv(v);auto [k,h]=EnumHW_inv(w);return DirectionNumberOnGrid(i,j,k,h);} // inline int ReverseDirectionNumberOnGrid( const int& n ){assert(0<=n&&n<4);return(n+2)%4;} // list<int> e[bound_N]; // // list<int> e[bound_HW]; // list<int> E( const int& i ) // { // list<int> answer = e[i]; // // 入力によらない処理 // return answer; // } // template <typename T> inline T add( const T& t0 , const T& t1 ) { return t0 + t1; } // template <typename T> inline const T& zero() { static const T z = 0; return z; } // template <typename T> inline T multiply( const T& t0 , const T& t1 ) { return t0 * t1; } // template <typename T> inline const T& one() { static const T o = 1; return o; } // inline CEXPR( ll , P , 998244353 ); // inline CEXPR( ll , P , 1000000007 ); int main() { UNTIE; LIBRARY_SEARCH; START_MAIN; // DEXPR( int , bound_T , 100000 , 100 ); // CIN_ASSERT( T , 1 , bound_T ); // REPEAT( T ){ // } // CIN( int , N ); // // CIN( ll , N ); SET_ASSERT( N , 1 , bound_N ); // // CIN( int , M ); // // CIN( ll , M ); // SET_ASSERT( M , 1 , bound_M ); // // CIN( int , K ); // // CIN( ll , K ); tuple<string,int,int> info[bound_N]; map<string,CoordinateCompress<int> > cc{}; CoordinateCompress<int> all_cc{}; FOR( i , 0 , N ){ CIN( string , X ); CIN( int , L ); CIN( int , R ); info[i] = { X , L , R }; auto& cc_X = cc[X]; cc_X.Insert( L ); cc_X.Insert( R ); all_cc.Insert( L ); all_cc.Insert( R ); } // CIN( string , S ); // CIN( string , T ); // SET_ASSERT( H , 1 , bound_H ); // SET_ASSERT( W , 1 , bound_W ); // TYPE_OF( bound_HW ) HW = TYPE_OF( bound_HW )( H ) * W; // assert( HW <= bound_HW ); // // CEXPR( int , bound_Ai , 10 ); // // CEXPR( int , bound_Ai , 100000 ); // 0が5個 // CEXPR( int , bound_Ai , 1000000000 ); // 0が9個 // // CEXPR( ll , bound_Ai , 1000000000000000000 ); // 0が18個 // // CEXPR( int , bound_Bi , bound_Ai ); // int A[N]; // ll A[N]; // // int A[bound_N]; // // ll A[bound_N]; // int B[N]; // // ll B[N]; // // int B[bound_N]; // // ll B[bound_N]; // FOR( i , 0 , N ){ // CIN( int , Ai ); // // CIN( ll , Ai ); // // CIN_ASSERT( Ai , 0 , bound_Ai ); // A[i] = Ai; // CIN( int , Bi ); // // CIN( ll , Bi ); // // CIN_ASSERT( Bi , 0 , bound_Bi ); // B[i] = Bi; // } // FOR( i , 0 , M ){ // CIN_ASSERT( ui , 1 , N ); // CIN_ASSERT( vi , 1 , N ); // ui--; // vi--; // e[ui].push_back( vi ); // e[vi].push_back( ui ); // } // CIN( int , Q ); DEXPR( int , bound_Q , 100000 , 100 ); CIN_ASSERT( Q , 1 , bound_Q ); tuple<int,string,int,int> query[bound_Q]; FOR( q , 0 , Q ){ CIN( int , type ); if( type == 1 ){ CIN( string , x ); CIN( int , t ); cc[x].Insert( t ); all_cc.Insert( t ); query[q] = { type , x , t , 0 }; } else if( type == 2 ){ CIN( int , t ); all_cc.Insert( t ); query[q] = { type , "" , t , 0 }; } else { CIN( string , x ); CIN( int , l ); CIN( int , r ); auto& cc_x = cc[x]; cc_x.Insert( l ); cc_x.Insert( r ); all_cc.Insert( l ); all_cc.Insert( r ); query[q] = { type , x , l , r }; } } map<string,int> diff{}; int length = 0; FOR_ITR( cc ){ diff[itr->first] = length; length += itr->second.size(); } IntervalAddBIT<int,(bound_N+bound_Q)*2> come{}; IntervalAddBIT<int,(bound_N+bound_Q)*2> count{}; FOR( i , 0 , N ){ auto& [X,L,R] = info[i]; auto& cc_X = cc[X]; int& diff_X = diff[X]; come.IntervalAdd( cc_X.GetOrder( L ) + diff_X , cc_X.GetOrder( R ) + diff_X , 1 ); count.IntervalAdd( all_cc.GetOrder( L ) , all_cc.GetOrder( R ) , 1 ); } FOR( q , 0 , Q ){ auto& [type,x,l,r] = query[q]; if( type == 1 ){ l = cc[x].GetOrder( l ) + diff[x]; COUT( ( come.IntervalSum( l , l ) > 0 ? "Yes" : "No" ) ); } else if( type == 2 ){ l = all_cc.GetOrder( l ); COUT( ( count.IntervalSum( l , l ) ) ); } else { int& diff_x = diff[x]; auto& cc_x = cc[x]; come.IntervalAdd( cc_x.GetOrder( l ) + diff_x, cc_x.GetOrder( r ) + diff_x , 1 ); count.IntervalAdd( all_cc.GetOrder( l ) , all_cc.GetOrder( r ) , 1 ); } } // ll guchoku = Guchoku(); // ll answer = 0; // if( answer == guchoku ){ // CERR( answer << " == " << guchoku ); // } else { // CERR( answer << " != " << guchoku ); // QUIT; // } // COUT( ( answer ) ); FINISH_MAIN; QUIT; }