Given an array, answer queries: "What is the -th smallest element in subarray ?" Example: Query : 3rd smallest in is .
This is solvable with wavelet trees, but persistent segment tree gives a clean solution. Build persistent segment tree on coordinate-compressed values.
Version contains elements . Constraints: up to elements and queries.