Doubt in---"Array Queries-I"

I am getting WA for all test cases.But I AM NOT Able to figure out error in my code/approach .Pls help me figure out error in code/approach.link to my code is–https://ide.codingblocks.com/s/81185

please give the code with proper indentation, your code is not understandable , use brackets , otherwise if and else will mix and not work properly.

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.