Campus Drive(CPC4) problem help!

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??


Check these submissions and this submission .
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.