[REDACTED]! Knowing that this may very well be the end of Art Academy, once and for all, he wants to rebel as much as possible during his final moments, and decides to show off what [REDACTED] despises the most: the art of math.
has been banished to the Ministry ofHe begins by creating an array of elements, indexed from to , initialized with the elements . There are queries that will need to be performed on this array.
The queries will be in the following format:
Format Description | Query Description |
---|---|
Let us define a polynomial function . For each element between and inclusive, increment by . | |
Calculate the sum of all the elements from to inclusive, modulo . Ensure that the result of the modulo is always positive. |
Unfortunately, even
forgets how to perform such difficult queries sometimes, so he is asking you for your help! Can you help perform queries on an array?Input Specification
On the first line, there will be two space-separated integers, and .
On the second line, there will be space-separated integers, , the initial values of the array. . denotes the absolute value symbol.
The next lines contain a query in the format specified above, where , , and . Note that for query , there will always be integers following the integer .
Output Specification
For each type query, output a single integer representing the result of the calculation on a newline.
Subtasks
For this problem, you will NOT be required to pass all the samples in order to receive points. In addition, you must pass all previous subtasks to earn points for a specific subtask.
Subtask | Points | Description |
---|---|---|
1 | 15 | . There will be no queries of type . |
2 | 35 | For all type queries, . |
3 | 50 | No further constraints. |
Sample Input 1
5 3
7 6 5 4 3
1 1 4 2 0 0 1
2 4 5
2 1 4
Sample Output 1
23
52
Explanation
In the first query, the function is , which is simply . The elements from index to are incremented by , , , and respectively, meaning that the new array is 8 10 14 20 3
.
The sum of the elements from index to is .
The sum of the elements from index to is .
Sample Input 2
10 3
-5 -4 -3 -2 -1 0 1 2 3 4
1 2 10 10 -1 1 -1 1 -1 1 -1 1 -1 1 -1
2 1 10
2 1 1
Sample Output 2
508532018
1000000002
Comments