Comments

O(Q * sqrt(M) * log(N))

Can somebody please explain to me why this code gets accepted, but during the contest I got on the same code WA? There is only one very small difference between those 2, the AC one has a forgotten cerr into it, you can check with a diff tool :)