Mo's Algorithm: DQUERY from SPOJ