


The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of each test case contains a single integer ‘N’ denoting the number of elements in the array.
The second line of each test case contains ‘N’ space-separated integers denoting the array ‘ARR’.
The third line of each test case contains an integer ‘Q’ denoting the number of queries.
The next ‘Q’ lines of each test case contain 3 space-separated integers denoting the following:
1. The first integer denotes the type of query. It can be either a ‘1’ or a ‘2’. 1 denotes range sum type query and 2 denotes update type query.
2. If the query is of the first type, the second and third integers on the same line denote ‘L’ and ‘R’ respectively which are the range of which we need to calculate its sum.
3. If the query of the second type, the second integer denotes ‘i’ the index of which the value is to be updated and the third integer denotes ‘X’ the updated value of the ‘i-th’ index.
For each query of the first type, print the sum of values with indices in the range of ‘L’ and ‘R’.
For queries of the second type, do not print anything just update the value in the given array.
You don't need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^5
1 <= Q <= 10^5
-10^9 <= ARR[i] <= 10^9
Where ‘N’ denotes the length of the array 'ARR', 'Q' denotes the number of queries, and ‘ARR[i]’ is the value of the element at index ‘i’.
Time Limit: 1 sec
We can take the following approach:
The idea is to do the given queries efficiently. We can do this in many different ways. One of them is using a Fenwick tree or a binary indexed tree.
We know that 7=2^2+2^1+2^0. So it to find sum of first 7 elements we can just find sum of first 4 then next 2 then then the last element .
The Fenwick tree for the above array will be:
We can see that the 2nd index stores the sum of the first and second elements. The fourth has the sum of all 4 elements. The 6th element has the sum of the 5th and 6th elements. The following diagram shows this more clearly:
log(8) is 3 and we can clearly see that we need to update 3 ranges.
Keeping in mind the above points we can take the following approach: