File tree Expand file tree Collapse file tree 3 files changed +14
-7
lines changed Expand file tree Collapse file tree 3 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ namespace cp_algo {
1111    size_t  order_of_bit (auto  x, size_t  k) {
1212        return  k ? std::popcount (x << (bit_width<decltype (x)> - k)) : 0 ;
1313    }
14-     //  Requires GCC  target("popcnt, bmi2")
14+     [[gnu:: target(" bmi2"  )]] 
1515    size_t  kth_set_bit (uint64_t  x, size_t  k) {
1616        return  std::countr_zero (_pdep_u64 (1ULL  << k, x));
1717    }
Original file line number Diff line number Diff line change 55namespace  cp_algo  {
66    //  coords is a range of reference_wrapper<T>
77    auto  compress_coords (auto  &coords) {
8-         std::vector<int > original;
8+         using  T = std::decay_t <std::unwrap_reference_t <
9+             std::ranges::range_value_t <decltype (coords)>
10+         >>;
11+         std::vector<T> original;
12+         if (empty (coords)) {
13+             return  original;
14+         }
915        original.reserve (size (coords));
1016        radix_sort (coords);
11-         int  idx = -1 , prev = -1 ;
17+         size_t  idx = -1 ;
18+         T prev = ~coords.front ();
1219        for (auto  &x: coords) {
1320            if (x != prev) {
1421                idx++;
Original file line number Diff line number Diff line change @@ -24,12 +24,12 @@ namespace cp_algo {
2424        if (empty (a)) {
2525            return ;
2626        }
27-         auto  mx  = std::ranges::max  (a);
28-         with_bit_floor (size (a), [&]<size_t  floor>() {
27+         auto  [mn, mx]  = std::ranges::minmax  (a);
28+         with_bit_floor< 1 > (size (a), [&]<size_t  floor>() {
2929            constexpr  int  base = std::min<size_t >(floor, 1  << 16 );
30-             for (int64_t  i = 1 ; i <= mx; i *= base) {
30+             for (int64_t  i = 1 ; i <= mx - mn ; i *= base) {
3131                count_sort<base>(a, [&](auto  x) {
32-                     return  x  / i % base;
32+                     return  (x - mn)  / i % base;
3333                });
3434            }
3535        });
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments