So I have an integer array in which I need to find the sum between range L to R
Also I need to add some value x(int) to range L to R i.e update operation.
I have solved these questions using fenwick tree range sum/update queries but this problem is little bit different.
The rule for finding the sum between ranges is that :
Sum(L,R) = ceil(arr[L]/5) + ceil(arr[(L+1)]/5) + ceil(arr[(L+2)]/5) + ...... + ceil(arr[R]/5)
For example -
arr = [2,4,6,8,1]
sum(1,4) = ceil(4/5) + ceil(6/5) + ceil(8/5) + ceil(1/5)
= 1 + 1 + 2 + 1
= 4
Now as we know that fenwick tree uses a BIT array in which the indexes stores the sum of some range values, so we cannot just find use the sum query and divide the resultant sum with 5 and take the ceil right ? as it will result in errors.
My approach : I am updating the BIT array with ceil(x/5) and then simply using the sum query sum(R)-sum(l-1) but it is obviously giving error values. How could I correct the resultant values ?