diff --git a/20240906/bitset.cpp b/20240906/bitset.cpp index fa319de..1bc2921 100644 --- a/20240906/bitset.cpp +++ b/20240906/bitset.cpp @@ -1,8 +1,10 @@ +#include #include #include #include -#include #include +#include +#include #include using namespace std; @@ -11,42 +13,84 @@ typedef int i8; const u8 MAX = 1e5+1; -constexpr std::array initLog2(){ +template +struct std::formatter> { + constexpr auto parse(format_parse_context& ctx)const { + return ctx.begin(); + } + + constexpr auto format(const std::vector& v, auto& ctx)const { + auto out = ctx.out(); + std::format_to(out, "["); + for (size_t i = 0; i < v.size(); ++i) { + if (i > 0) { + std::format_to(out, ", "); + } + std::format_to(out, "{}", v[i]); + } + return std::format_to(out, "]"); + } +}; + +constexpr std::array initLog2() { std::array log2{}; - log2[1]=0; - for(int i=2;i<=(int)MAX-1;i++){ - log2[i]=log2[i/2]+1; + log2[1] = 0; + for (int i = 2; i <= (int)MAX - 1; i++) { + log2[i] = log2[i / 2] + 1; } return log2; } -class BitIntSet{ +class BitIntSet { private: - constexpr static const std::array log2=initLog2(); + constexpr static const std::array log2 = initLog2(); public: i8 data; - - explicit BitIntSet(i8 n):data{n}{ - // checkLog2IsInitalized(); + + constexpr explicit BitIntSet(i8 n) : data{n} {} + + constexpr int getLowbit() const { + return this->data & ((~this->data) + 1); } - int getLowbit()const{ - return this->data&((~this->data)+1); + + constexpr int getLowbit(u8 n) const { + return n & ((~n) + 1); } - int getLowbit(u8 n)const{ - return n&((~n)+1); - } - std::vector get1Dir()const{ + + constexpr std::vector get1Dir() const { std::vector ret; - int temp=this->data; - while(temp>0){ - ret.push_back(log2[this->getLowbit()]); - temp-=getLowbit(temp); + int temp = this->data; + while (temp != 0) { + // #ifndef NDEBUG + // std::cout< +void print(const Args&...args){ + ((std::cout< +void println(const Args&...args){ + ((std::cout<