i Calculate the left and right child answer then i combine as;
parent = left + right*2^LengthOfLeftChild
i used indexing from last as opposed to what is mentioned in the question. so when i take input i made sure i modify the input before passing the range values.
Please Check the code. It works on the test cases provided but gives wrong answer when submitting.
I also used lazy updates please check if the code for lazy updates is correct or not.
Code Link: https://ide.codingblocks.com/s/109875
@Saurabh-Kumar-1331476656958199
Thank You.