number of subsets having xor < x
| 68 | } |
| 69 | // number of subsets having xor < x |
| 70 | T count_lt(T x) { |
| 71 | if (x < 0) { |
| 72 | return 0; |
| 73 | } |
| 74 | T ans = 0; |
| 75 | T cnt = ((T)1 << sz); |
| 76 | T mask = 0; |
| 77 | for (int i = B - 1; i >= 0; i--) { |
| 78 | // at this stage, all prev > i th bits in mask and x are the same |
| 79 | if (basis[i]) { |
| 80 | if (x >> i & 1) { |
| 81 | ans += (cnt >> 1); |
| 82 | if (!(mask >> i & 1)) { |
| 83 | mask ^= basis[i]; |
| 84 | } |
| 85 | } else { |
| 86 | if (mask >> i & 1) { |
| 87 | mask ^= basis[i]; |
| 88 | } |
| 89 | } |
| 90 | cnt >>= 1; |
| 91 | } else { |
| 92 | if ((x >> i & 1) != (mask >> i & 1)) { |
| 93 | if (x >> i & 1) { |
| 94 | return ans + cnt; |
| 95 | } else { |
| 96 | return ans; |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | return ans; |
| 102 | } |
| 103 | }; |
| 104 | |
| 105 | void solve() { |
nothing calls this directly
no outgoing calls
no test coverage detected