finding k-th zero
- count numbers of zeros for each child
- start at root and descend based on what side k would be on
finding first i where ai≥x
- create max segment tree
- start at root, if l≥x then descend l, else descend r
- repeat until base, finding i
kth-smallest
- assemble a as frequency array
- convert to bits; 1 for has i, 0 for no i
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 0s as empty and 1s as full
- for each node, store max amount of consecutive 0s (seg), maximum prefix of 0s (pref), and maximum suffix of 0s (suff)
- can merge prefs and suffs together accordingly when moving up, so seg=max(suffl+prefr,segl,segr)
- for pref and suff, based on if they’re the entire length of the segment
- if prefl=lenl, pref=prefl+prefr, else pref=prefl
- if suffr=lenr, suff=suffl+suffr, else suff=suffr