Range product queries
InterviewTime limit1sMemory limit256 MB
Answer range product queries modulo 1,000,000,007 on a sequence with point updates.
- Level
Medium4 of 10
- Topics
- Segment tree
- Solved
- No attempts yet
Problem
You are given a sequence of numbers. Elements of the sequence change often, and between those changes you have to compute the product of some range.
For example, take the sequence 1, 2, 3, 4, 5. Change the third number to 6 and ask for the product from the second number to the fifth, and the answer is 240. Then change the fifth number to 2 and ask for the product from the third number to the fifth, and the answer is 48.
Given changes and range product queries mixed together, write a program that computes the product for each query.
Input
The first line contains the count of numbers (), the number of changes (), and the number of range product queries (), separated by spaces.
The next lines contain the elements of the sequence in order, one per line.
The following lines each contain three integers , , and . If is 1, change the -th number to . If is 2, compute the product from the -th number to the -th number. On a line where is 2, holds.
Every number in the input is an integer between 0 and 1,000,000, inclusive.
Output
Print one line for each product query, in the order the queries are given, for a total of lines. Each line holds the product of that range modulo 1,000,000,007.