When values range up to but there are only distinct values, compress:
function compress(arr)
sorted := sort(unique(arr))
mapping := map from value to compressed index
for i from 0 to length(sorted) - 1
mapping[sorted[i]] := i
for i from 0 to length(arr) - 1
arr[i] := mapping[arr[i]]
Now alphabet size instead of .
This reduces wavelet tree depth from 30 to .
Always compress when values are sparse. The queries work the same; just remember to translate results back if needed.