#K38567. Range Product Queries
Range Product Queries
Range Product Queries
You are given an array of n integers and a sequence of queries. There are two types of queries:
- Update Query:
1 x y
— update the element at position x with the value y. - Range Query:
2 l r
— compute the product of the elements from index l to r (1-indexed) modulo \(10^9+7\).
For range queries, you may use the formula \[ \text{product}(l, r)=\frac{P(r)}{P(l-1)} \pmod{10^9+7} \] where \(P(i)=a_1\times a_2\times\cdots\times a_i\) and the division is performed using the modular inverse. Implement the queries accordingly.
inputFormat
The input is given in the following format:
- The first line contains an integer n denoting the number of elements in the array.
- The second line contains n space-separated integers representing the array.
- The third line contains an integer q denoting the number of queries.
- The following q lines each contain three space-separated integers representing a query. The first integer is the query type (1 for update and 2 for range query). For an update query, the next two integers are x and y (set the element at position x to y). For a range query, the next two integers are l and r (query the product from index l to r).
outputFormat
For every range query (type 2), output the product of the specified subarray modulo \(10^9+7\> on a new line.
## sample5
1 2 3 4 5
5
2 1 3
1 3 6
2 1 3
2 3 5
1 5 2
6
12
120
</p>