gettin runtime error

my code is working properly until query loop and i am answering the query in O(1) time but still ideone shows runtime error. rest code is working fine please help asap and thanks in advance

Declare your arrays after you have taken n as input, you will not get runtime error.