Practice · 2 of 4
Distinct Values in a Range
CHALLENGE
Difficulty: advanced+25 XP
**Bài toán.** An array of n integers (values up to 10^6), q queries
l r: print the number of distinct values in a[l..r].
**Constraints:** 1 ≤ n, q ≤ 50 000. Offline sweep by right end + Fenwick:
O((n + q) log n).
Press Submit to check your solution.
Back to lesson: Practice: Fenwick Variant Drills