Problems > Range Products, Zeros Included

Range Products, Zeros Included

Difficulty: 1600 3500 ms 128 MB

math prefix-sums

Answer Q range-product queries modulo 109+7 on an array that may contain ZEROS.

Input: the first line has N and Q; the second line has N non-negative integers; the next Q lines have L and R.

Output: Q lines: the product of aL..R mod 109+7.

Constraints:

  • 1 ≤ N, Q ≤ 105
  • 0 ≤ ai ≤ 109

Sample Tests

Input 1
5 2
2 3 0 4 5
1 2
2 4
Output 1
6
0
Input 2
1 1
0
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.