Why it matters
Mo's algorithm enables efficient batch range query processing. Competitive standard.
Advertisement
The architecture
Sort queries by (bucket of L, R). Bucket size √n.
Move L, R incrementally; update count.
Advertisement
How it works end to end
Total moves: O((n+q)√n) amortized.
Requires: online 'add/remove element' operations.
Extensions: Mo's on tree, with updates.