#C10857. Arithmetic Sequence Query Operations

    ID: 40108 Type: Default 1000ms 256MiB

Arithmetic Sequence Query Operations

Arithmetic Sequence Query Operations

In this problem, you are given an arithmetic sequence with first term (A) and common difference (D). The (i)-th term of the sequence is defined as (a_i = A + (i-1) \times D). You need to answer (Q) queries. Each query is of one of the following two types:

  1. Type 1: Given integers (L) and (R), compute the sum [ S = \sum_{i=L}^{R} a_i \quad = \quad (R-L+1) \times \frac{(a_L + a_R)}{2} ]

  2. Type 2: Given integers (L) and (R), compute the product [ P = \prod_{i=L}^{R} a_i \mod 1000000007 ]

The input is given via standard input and the output should be printed to standard output with each answer on a new line. Note that indices are 1-indexed. Use efficient computations as required. (For products use modulo arithmetic with modulo (10^9+7)).

inputFormat

The first line contains three integers (A), (D), and (Q), where (A) is the first term of the arithmetic sequence, (D) is the common difference, and (Q) is the number of queries. Each of the next (Q) lines contains three integers (T), (L), and (R):

  • (T = 1) indicates a sum query.
  • (T = 2) indicates a product query (the product must be computed modulo (10^9+7)). (L) and (R) denote the starting and ending indices (1-indexed) of the segment of the sequence.

outputFormat

For each query, output the result on a new line. For sum queries, print the exact sum; for product queries, print the product modulo (10^9+7).## sample

2 3 5
1 1 3
1 2 4
2 1 2
2 3 5
2 1 1
15

24 10 1232 2

</p>