Here is my AC code: https://hastebin.com/ewobuzater.cpp
It uses offline BIT + sorting.
Here is the strange thing: que works perfectly fine, but if you change it to que it will segfault. However, it is zero based indexing and q is at max 200000.
Can anyone think of a case where que faces out of bound access?