File tree Expand file tree Collapse file tree 7 files changed +35
-31
lines changed Expand file tree Collapse file tree 7 files changed +35
-31
lines changed Original file line number Diff line number Diff line change @@ -290,10 +290,9 @@ namespace cp_algo::math::fft {
290290        }
291291        return  std::max (flen, std::bit_ceil (as + bs - 1 ) / 2 );
292292    }
293-     static  const  int  naive_threshold = 64 ;
294293    void  mul_truncate (auto  &a, auto  const & b, size_t  k) {
295294        using  base = std::decay_t <decltype (a[0 ])>;
296-         if (std::min ({k, size (a), size (b)}) < naive_threshold ) {
295+         if (std::min ({k, size (a), size (b)}) < magic ) {
297296            mul_slow (a, b, k);
298297            return ;
299298        }
Original file line number Diff line number Diff line change 1- #ifndef  CP_ALGO_BIT_HPP
2- #define  CP_ALGO_BIT_HPP 
3- #include  < immintrin.h> 
4- #include  < cstdint> 
5- #include  < array> 
6- #include  < bit> 
7- namespace  cp_algo  {
8-     template <typename  Uint>
9-     constexpr  size_t  bit_width = sizeof (Uint) * 8 ;
10-     template <size_t  maxc, typename  Uint = uint64_t >
11-     using  popcount_array = std::array<int , maxc / bit_width<Uint> + 1 >;
12- 
13-     size_t  order_of_bit (auto  x, size_t  k) {
14-         return  k ? std::popcount (x << (bit_width<decltype (x)> - k)) : 0 ;
15-     }
16-     //  Requires GCC target("popcnt,bmi2")
17-     size_t  kth_set_bit (uint64_t  x, size_t  k) {
18-         return  std::countr_zero (_pdep_u64 (1ULL  << k, x));
19-     }
20- 
1+ #ifndef  CP_ALGO_STRUCTURES_BIT_ARRAY_HPP
2+ #define  CP_ALGO_STRUCTURES_BIT_ARRAY_HPP 
3+ #include  " cp-algo/util/bit.hpp" 
4+ namespace  cp_algo ::structures {
215    template <size_t  N, typename  Uint = uint64_t >
226    struct  bit_array  {
237        static  constexpr  size_t  width = bit_width<Uint>;
@@ -41,4 +25,4 @@ namespace cp_algo {
4125        }
4226    };
4327}
44- #endif  //  CP_ALGO_BIT_HPP 
28+ #endif  //  CP_ALGO_STRUCTURES_BIT_ARRAY_HPP 
Original file line number Diff line number Diff line change 11
22#ifndef  CP_ALGO_STRUCTURES_BITPACK_HPP
33#define  CP_ALGO_STRUCTURES_BITPACK_HPP 
4- #include  " cp-algo/bit .hpp" 
4+ #include  " bit_array .hpp" 
55#include  < cstdint> 
66#include  < cstddef> 
77#include  < string> 
Original file line number Diff line number Diff line change 55#include  < iostream> 
66#include  < vector> 
77#include  < string> 
8- #include  " ../bump_alloc.hpp" 
8+ #include  " ../util/ bump_alloc.hpp" 
99namespace  cp_algo ::structures {
1010    template <int  sigma = 26 , char  mch = ' a'  >
1111    struct  eertree  {
Original file line number Diff line number Diff line change 11#ifndef  CP_ALGO_STRUCTURES_FENWICK_SET_HPP
22#define  CP_ALGO_STRUCTURES_FENWICK_SET_HPP 
33#include  " fenwick.hpp" 
4- #include  " cp-algo/bit .hpp" 
4+ #include  " bit_array .hpp" 
55namespace  cp_algo ::structures {
6+     template <size_t  maxc, typename  Uint = uint64_t >
7+     using  popcount_array = std::array<int , maxc / bit_width<Uint> + 1 >;
68    //  fenwick-based set for [0, maxc)
79    template <size_t  maxc, typename  Uint = uint64_t >
810    struct  fenwick_set : fenwick<int , popcount_array<maxc, Uint>> {
@@ -24,15 +26,15 @@ namespace cp_algo::structures {
2426        }
2527        void  insert (size_t  x) {
2628            if (bits.test (x)) return ;
29+             Base::add (x / word, 1 );
2730            bits.flip (x);
2831            sz++;
29-             Base::add (x / word, 1 );
3032        }
3133        void  erase (size_t  x) {
3234            if (!bits.test (x)) return ;
35+             Base::add (x / word, -1 );
3336            bits.flip (x);
3437            sz--;
35-             Base::add (x / word, -1 );
3638        }
3739        size_t  order_of_key (size_t  x) const  {
3840            return  Base::prefix_sum (x / word) + order_of_bit (bits.word (x / word), x % word);
Original file line number Diff line number Diff line change 1+ #ifndef  CP_ALGO_UTIL_BIT_HPP
2+ #define  CP_ALGO_UTIL_BIT_HPP 
3+ #include  < immintrin.h> 
4+ #include  < cstdint> 
5+ #include  < array> 
6+ #include  < bit> 
7+ namespace  cp_algo  {
8+     template <typename  Uint>
9+     constexpr  size_t  bit_width = sizeof (Uint) * 8 ;
10+ 
11+     size_t  order_of_bit (auto  x, size_t  k) {
12+         return  k ? std::popcount (x << (bit_width<decltype (x)> - k)) : 0 ;
13+     }
14+     //  Requires GCC target("popcnt,bmi2")
15+     size_t  kth_set_bit (uint64_t  x, size_t  k) {
16+         return  std::countr_zero (_pdep_u64 (1ULL  << k, x));
17+     }
18+ }
19+ #endif  //  CP_ALGO_UTIL_BIT_HPP
Original file line number Diff line number Diff line change 1- #ifndef  CP_ALGO_BUMP_ALLOC_HPP 
2- #define  CP_ALGO_BUMP_ALLOC_HPP 
1+ #ifndef  CP_ALGO_UTIL_BUMP_ALLOC_HPP 
2+ #define  CP_ALGO_UTIL_BUMP_ALLOC_HPP 
33#include  < cstddef> 
44namespace  cp_algo  {
55    char  buf[450  << 20 ] alignas (32 );
@@ -16,4 +16,4 @@ namespace cp_algo {
1616        void  deallocate (T*, size_t ) {}
1717    };
1818}
19- #endif  //  CP_ALGO_BUMP_ALLOC_HPP 
19+ #endif  //  CP_ALGO_UTIL_BUMP_ALLOC_HPP 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments