Campus Drive(CPC4) problem help!

problem
I have used sqrt decomposition to solve the problem and i am passing every test case except one from subtask 1.I am getting a SIGSEGV error on that one.Could anyone check out my code and help me out??
mysol

thanks.

Check these submissions https://www.codechef.com/viewsolution/17246926 and this submission https://www.codechef.com/viewsolution/17246962 .
Only difference is value of max. But I am not getting why one submission is getting seg fault for subtask 1 when max is 10^5+7 .
Maybe you can understand and
your solution may be getting seg due the same reason.