There is some logical error

hello @asinghal1_be19

check now->

plz check what is the error in it

@asinghal1_be19
a) u r not reading number of queries .

b) u r time complexity will be q * n which will give tle.

optimise ur code by doing preprocessing.

refer this->

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

it is showing segmentation fault

in the updated code u provided