Is it possible to query number of distinct integers in a range in O(lg N)?
问题 I have read through some tutorials about two common data structure which can achieve range update and query in O(lg N): Segment tree and Binary Indexed Tree (BIT / Fenwick Tree). Most of the examples I have found is about some associative and commutative operation like "Sum of integers in a range", "XOR integers in a range", etc. I wonder if these two data structures (or any other data structures / algorithm, please propose) can achieve the below query in O(lg N)? (If no, how about O(sqrt N))