Problems > Count Evens in a Range

Count Evens in a Range

Difficulty: 1100 3000 ms 128 MB

prefix-sums

Answer Q independent queries on a fixed array: each query gives L and R (1-based, inclusive) and asks for the number of even values of aL..R.

Input: the first line has N and Q; the second line has N integers; each of the next Q lines has L and R.

Output: Q lines — the answer per query.

Constraints:

  • 1 ≤ N, Q ≤ 104
  • −109 ≤ ai ≤ 109

Sample Tests

Input 1
5 2
1 -2 3 -4 5
1 3
2 5
Output 1
1
2
Input 2
1 1
7
1 1
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.