Array Queries (Wrong answer)

I am building segment by calling f(i,k) for each element of array and later storing sum of both the subtrees in node. But this approach is giving me wrong answer and also run error in case of update operation. Please suggest possible changes to make my code work.

for every array element you are iterating k time how this sol is going to work ? always think about the time complexity and then start.

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.