finding -th zero

  • count numbers of zeros for each child
  • start at root and descend based on what side would be on

finding first where

  • create segment tree
  • start at root, if then descend , else descend
  • repeat until base, finding

th-smallest

  • assemble as frequency array
  • convert to bits; 1 for has , 0 for no
int v = 1;
 
if (st[v] < k) return -1;
 
while (v < len) {
    if (st[v * 2] >= k) {
        v = v * 2;
    } else {
        k -= st[v * 2];
        v = v * 2 + 1;
    }
}
 
return v - len;

contiguous blocks

  • designate s as empty and s as full
  • for each node, store max amount of consecutive s (), maximum prefix of s (), and maximum suffix of ()
  • can merge s and s together accordingly when moving up, so
  • for and , based on if they’re the entire length of the segment
    • if , , else
    • if , , else