Given an array of integers and queries, each query asks: how many distinct values are in range ? Constraints: , values up to .
This problem is perfect for MO's algorithm.
Segment trees can't easily count distinct values, but extending a range by one element is simple: check if you've seen this value before in the current range. Before reading the solution, think about how you'd implement the and functions.