Is it possible to query number of distinct integers in a range in O(lg N)?

后端 未结 5 1426
滥情空心
滥情空心 2020-12-13 15:02

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 T

5条回答
  •  渐次进展
    2020-12-13 15:34

    The given problem can also be solved using Mo's (offline) algorithm also called Square Root decomposition algorithm.

    Overall time complexity is O(N*SQRT(N)).

    Refer mos-algorithm for detailed explanation, it even has complexity analysis and a SPOJ problem that can be solved with this approach.

提交回复
热议问题