 1

# Count Even Or Odd

Difficulty: HARD Contributed By
Ankit Kharb
Avg. time to solve
30 min
Success Rate
60%

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.
``````
##### Sample Input 1 :
``````6
1 2 3 4 5 6
4
1 1 4
2 0 3
0 4 4
1 0 5
``````
##### Sample Output 1 :
``````2
2
4
``````
##### Explanation Of Sample Input 1 :
``````The first query consists of 1 1 4 .It means we have to count the number of even numbers from 1st index to 4th index. Hence even numbers in the given range are 2 and 4. So the answer for the first query is 2.So the answer is 2.

The second query consists of 2 0 3. It means we have to count odd numbers from 0th index to 3rd index. Hence odd numbers in the given range are 1 and 3.So the answer is 2.

The third query consists of 0 4 4. It means we have to modify the element at 4th index to 4. So the array becomes 1 2 3 4 4 6.

The fourth query consists of 1 0 5 .It means we have to count even numbers from 0th index to 5th index. Hence even numbers in the given range are 2 4 4 6. So the answer is 4.
``````
##### Sample Input 2 :
``````16
525 327 227 725 833 860 255 803 625 766 200 383 712 935 422 937
9
2 12 14
1 14 15
1 1 6
1 10 15
0 10 430
2 2 12
0 10 905
2 4 10
1 15 15
``````
##### Sample Output 2 :
``````1
1
1
3
7
5
0
``````   Console