Data Structures19 sections · 729 units
Open in Course

Problem - Range Frequency Query

Count specific value

Design a data structure for an array.

Answer queries: "How many times does value vv appear in A[l..r]A[l..r]?" Example: A=[12,33,4,56,22,2,34,33,22,12,34,56]A = [12, 33, 4, 56, 22, 2, 34, 33, 22, 12, 34, 56] Query (1,10,33)(1, 10, 33) returns 22 (indices 1 and 7).

You're solving the frequency counting problem that wavelet trees handle efficiently. Constraints: up to 10510^5 elements, up to 10510^5 queries.