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 {
290
290
}
291
291
return std::max (flen, std::bit_ceil (as + bs - 1 ) / 2 );
292
292
}
293
- static const int naive_threshold = 64 ;
294
293
void mul_truncate (auto &a, auto const & b, size_t k) {
295
294
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 ) {
297
296
mul_slow (a, b, k);
298
297
return ;
299
298
}
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 {
21
5
template <size_t N, typename Uint = uint64_t >
22
6
struct bit_array {
23
7
static constexpr size_t width = bit_width<Uint>;
@@ -41,4 +25,4 @@ namespace cp_algo {
41
25
}
42
26
};
43
27
}
44
- #endif // CP_ALGO_BIT_HPP
28
+ #endif // CP_ALGO_STRUCTURES_BIT_ARRAY_HPP
Original file line number Diff line number Diff line change 1
1
2
2
#ifndef CP_ALGO_STRUCTURES_BITPACK_HPP
3
3
#define CP_ALGO_STRUCTURES_BITPACK_HPP
4
- #include " cp-algo/bit .hpp"
4
+ #include " bit_array .hpp"
5
5
#include < cstdint>
6
6
#include < cstddef>
7
7
#include < string>
Original file line number Diff line number Diff line change 5
5
#include < iostream>
6
6
#include < vector>
7
7
#include < string>
8
- #include " ../bump_alloc.hpp"
8
+ #include " ../util/ bump_alloc.hpp"
9
9
namespace cp_algo ::structures {
10
10
template <int sigma = 26 , char mch = ' a' >
11
11
struct eertree {
Original file line number Diff line number Diff line change 1
1
#ifndef CP_ALGO_STRUCTURES_FENWICK_SET_HPP
2
2
#define CP_ALGO_STRUCTURES_FENWICK_SET_HPP
3
3
#include " fenwick.hpp"
4
- #include " cp-algo/bit .hpp"
4
+ #include " bit_array .hpp"
5
5
namespace cp_algo ::structures {
6
+ template <size_t maxc, typename Uint = uint64_t >
7
+ using popcount_array = std::array<int , maxc / bit_width<Uint> + 1 >;
6
8
// fenwick-based set for [0, maxc)
7
9
template <size_t maxc, typename Uint = uint64_t >
8
10
struct fenwick_set : fenwick<int , popcount_array<maxc, Uint>> {
@@ -24,15 +26,15 @@ namespace cp_algo::structures {
24
26
}
25
27
void insert (size_t x) {
26
28
if (bits.test (x)) return ;
29
+ Base::add (x / word, 1 );
27
30
bits.flip (x);
28
31
sz++;
29
- Base::add (x / word, 1 );
30
32
}
31
33
void erase (size_t x) {
32
34
if (!bits.test (x)) return ;
35
+ Base::add (x / word, -1 );
33
36
bits.flip (x);
34
37
sz--;
35
- Base::add (x / word, -1 );
36
38
}
37
39
size_t order_of_key (size_t x) const {
38
40
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
3
3
#include < cstddef>
4
4
namespace cp_algo {
5
5
char buf[450 << 20 ] alignas (32 );
@@ -16,4 +16,4 @@ namespace cp_algo {
16
16
void deallocate (T*, size_t ) {}
17
17
};
18
18
}
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