At first I thought I was getting MLE for using maps, then I used vector for mapping the elements of list. Not to mention, the number of elements in which test case I am getting MLE is surprisingly small. It's only 1000 * 2 items in array at most.
Now, I created a separate vector to store queries, it's a 2d vector. I am using first dimension to store the index where the query starts. The second dimension implies the number of queries in that index. This is the only thing that looks sus to me. Otherwise I don't get the cause of MLE