Mo's Algorithm
Standard Mo's Algorithm
Concept
The standard Mo's algorithm can solve certain interval problems that do not require online processing. It optimizes complexity by processing queries in an optimal order using brute force.
Consider block division. Divide the array into several blocks of length $ \sqrt{n} $. Sort the queries based on the block numb ...
Posted on Thu, 29 Oct 2026 16:15:58 +0000 by Dan06
Rollback Mo's Algorithm
Applicable Scenarios
Offline problems where expanding intervals is easier to maintain than shrinking.
Variants exist for "remove-only" Mo's algorithm.
Example Problem: P5906 [Template] Rollback Mo's Algorithm
Given an array, process multiple queries to find the maximum distance between two equal elements within a given interval.
Con ...
Posted on Mon, 14 Sep 2026 16:14:11 +0000 by Azala