Cover them all ! how to apply BIT

How to apply fenwick tree on this problem. What is the logic behind the solution??

Hey @utkarsh.lal9430310535

Keep 3 fenwick trees. In one let’s say current soldier position is X then add -X to all values from [ X , max ] and 1 to cnt tree from [X , max ] . In the other add -(max-X) to all values less than X.
Before making these updates, add value t2[X]*bomb-t1[X]. Then add (Y-t2[X])*bomb-t3[X] where Y is number of elements processed before X.

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.