Data Structures19 sections · 729 units
Open in Course

MO's with Expensive Operations

When add/remove costs more

If addadd and removeremove take O(f)O(f) time each, MO's total complexity becomes O((n+q)nf)O((n + q)\sqrt{n} \cdot f).

For example, if you're maintaining a sorted structure with O(logn)O(\log n) insert/delete: Total time: O((n+q)nlogn)O((n + q)\sqrt{n} \cdot \log n) This is still often better than O(nq)O(nq) naive approach.

But for tight limits, consider if a different technique (like merge sort tree or persistent segment tree) would be faster. The beauty of MO's is its flexibility. Any problem with efficient extend/shrink operations can use it.