Cheerio Contest 2 P5 - Subsequence Queries

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 2.0s
Memory limit: 512M

Authors:
Problem types

Given an array a of N integers, support Q queries of the following type:

l r return the number of subsequences between index l to r (inclusive) which have an even sum.

As the results of these queries may be extremely large, output them modulo 109+7.

A subsequence can be created from a by deleting some elements (possibly none, but not all). Two subsequences are different if one contains an index from the original array that the other does not have.

Constraints

For all subtasks:

  • 1N,Q,ai106
  • 1lrN
Points Awarded Additional Constraints
3 points All ai are even
5 points 1N,Q3×103
7 points No further constraints

Input Specification

The first line contains two space-separated integers N and Q.

The next line contains N space-separated integers — the array a.

The next Q lines each contain two space-separated integers li, and ri, denoting the ith query.

Output Specification

Output the answer to each query in order on separate lines.

Sample Input

Copy
6 1
4 3 1 2 5 7
2 4

Sample Output

Copy
3

Comments

There are no comments at the moment.