WA IN SPOG PROBLEM D QUERY

PLEASE HELP ME FIND MISTAKE IN MY CODE.
PROBLEM LINK- https://www.spoj.com/problems/DQUERY/2
Source Code - https://ideone.com/NyhLqI1

Link expired, but I guess just making set, clearing it for every query, and then inserting elements and return size of set, would give AC.

I didn’t understand how it will work. Because I am storing the queries in the MultiSet.
Basically Mo’s Algorithm.
Source Code -
https://www.codechef.com/viewsolution/24851617