MO's algorithm is a powerful offline technique for answering range queries when you can't use segment trees directly.
Here's the trick: if you have the answer for , you can extend to , , , or cheaply (often ).
The naive approach processes queries in order, but moving the range boundaries can jump wildly. MO's algorithm reorders queries to minimize total movement. By sorting queries cleverly, you ensure the total boundary movement is instead of .