Data Structures19 sections · 729 units
Open in Course

MO's with Updates

Time as third dimension

Standard MO's handles read-only queries. What if you have point updates mixed with queries? Treat time as a third dimension.

Each query now has (l,r,t)(l, r, t) where tt is the timestamp (number of updates before this query).

Sort by (l/B,r/B,t)(\lfloor l/B \rfloor, \lfloor r/B \rfloor, t) with block size B=n2/3B = n^{2/3}. You now have three pointers: currentLcurrentL, currentRcurrentR, and currentTcurrentT.

Moving currentTcurrentT applies or undoes updates. Complexity: O(n5/3)O(n^{5/3}) with the optimal block size.