I have a large array of bits of length $N$.
The query $f(k, m)$ means "find $kth$ zero in the array and the next $m-1$ zeros after it", $k \in [0, N-1], m \ll N$
Currently I use a segment tree over the bit array and my approaches were:
- use kth zero search procedure $m$ times in $O(m \log{N})$
- use the same kth zero search procedure but with divide-and-conquer approach:
- find the first $0th$ and the last $(m-1)th$ zero while also finding their LCA subtree
- find $(m/2)th$ zero in the LCA subtree
- recursively do 1. and 2. for both $0th$ and $(m / 2)th$ pair and $(m / 2)th$ and $(m-1)th$ pair
- maintain a link to the next zero for each member of the array, this gives $O(\log{N} + m)$ time but complicates array updates and requires additional $O(N)$ memory
I want any solution with better than $O(m \log{N})$ time.
I'm ready to switch to any other data structure if necessary.
Besides the aforementioned query the requirements are:
- spatial complexity is $O(N)$
- initialization in $O(N)$
- update after a single bit in array is flipped in $O(logN)$