When Removal Is Hard

Your per-element state supports add but has no sensible remove: you are maintaining a maximum, or a convex hull, or a DSU. Which Mo's variant applies?

A

Two-dimensional Mo (二维莫队). Sort as usual, but block both endpoints and order the queries by the resulting pair. Within a block, extend both pointers from a fixed corner and undo the extension after each query.

B

Rollback Mo (回滚莫队). Sort as usual, but never move a pointer in the direction that would require a removal. Within a block, extend from a fixed left boundary and undo the whole extension after each query.

C

Mo with modifications (带修莫队). Sort as usual, but add a third pointer over the timeline that walks forward and back. Within a block, roll time to each query's timestamp and undo the whole walk after each query.

D

Mo on trees (树上莫队). Sort as usual, but move the pointers over an Euler tour so that a subtree becomes contiguous. Within a block, toggle each node on entry and off on exit and undo the whole toggle after each query.