


0 x y
1 x y
2 x y
The first line of the test case contains a single integer ‘N’ denoting the size of the ‘arr’ array.
The second line of each test case contains ‘N’ space-separated integers denoting the elements 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:
0 x y - modify the number at index x to y.
1 x y - count the number of even numbers in range x to y inclusive.
2 x y - count the number of odd numbers in range x to y inclusive.
For each query, print an integer denoting the answer.
The output of each query will be printed in a separate line.
1 <= N, Q <= 10^5
0 <= l <= r <= N - 1
0 <= arr[i] <= 10 ^ 9
1 <= x <= N
0 <= y <= 10 ^ 9
Where 'arr[i]' denotes the 'ith' element of arr.
Time limit: 1 sec
You do not need to print anything, it has already been taken care of. Just implement the given function.
The key idea is to process the queries as asked.
The main idea is to process the queries efficiently we will use a segment tree. To know more about segment tree refer to this:- https://cp-algorithms.com/data_structures/segment_tree.html
At each node in the segment tree, we will store a number of elements that are even which are within the range of the segment. In the build function of the segment tree, the number of elements which are even corresponding to the parent node will be the sum of left and right child nodes.
segment[parent] = segment[leftChild] + segment[rightChild]
The main idea is to process the queries efficiently we will use the Fenwick tree. To know more about the Fenwick tree refer to this https://cp-algorithms.com/data_structures/fenwick.html
Sum of Shadows
Chocolate and Sweetness
Chocolate and Sweetness
Chocolate and Sweetness
Chocolate and Sweetness
Range Minimum Query
Range Minimum Query
Range Minimum Query
Range Minimum Query
Ninja and Tree
Distinct Queries on Tree