Minimum reputation to comment is 50. I just gave you 30 to help.
Thanx mate
Not that I know of, but this is a good tutorial for the data structure used here by @nilesh3105: Disjoint Sparse Table
thanks for your code. i understood everything from your code.