# Count Even Or Odd

Posted: 27 Apr, 2021
Difficulty: Hard

## PROBLEM STATEMENT

#### Query 0 :

``````0 x y
``````

#### Query 1 :

``````1 x y
``````

#### Query 2 :

``````2 x y
``````

#### This operation counts the number of odd numbers in range x to y inclusive.

##### Input Format :
``````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.
``````
##### Output Format :
``````For each query, print an integer denoting the answer.

The output of each query will be printed in a separate line.
``````
##### Constraints :
``````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
``````
##### Note :
``````You do not need to print anything, it has already been taken care of. Just implement the given function.
`````` Approach 1

The key idea is to process the queries as asked.

• For query of type 0 simply just update arr[i] to x.
• For query of type 1 simply run a loop from ‘l’ to ‘r’ and count the number of elements that are even.
• For query of type 2 simply run a loop from ‘l’ to ‘r’ and count the number of elements that are even.