03 Jun PMCA Friday 19:00 Python Homework 20.05.29.
Question:
Rory is playing with an array A consisting of N integer elements indexed from 1 to N and a positive integer M. Rory will perform Q operations. Each operation is either type 1 or type 2.
Type 1 operation is in the form 1 l r x. You should add x to each element in A[l], A[l + 1], …, A[r].
Type 2 operation is in the form 2 l r. You should output the sum (A[l]M + A[l + 1]M + … + A[r]M) mod M (MOD is calculate remainder of division, it is % in python).
Input Specification
The first line of input will contain three integers M, N, and Q.
The second line of input will contain N elements, the original elements of array A in the order A[1], A[2], …, A[N].
The next Q lines of input will contain an operation, either in the form 1 l r x for an operation of type 1 or 2 l r for an operation of type 2.
Output Specification
For each operation of type 2, output the answer on a new line.
Sample Input
2 5 3
1 2 3 4 5
2 1 4
1 2 5 7
2 1 5
Sample Output
0
1
Explanation
For the first operation, 12+22+32+42=30, and 30 mod 2 = 0.
For the second operation, the array A is now 1, 9, 10, 11, 12.
For the third operation, 12+92+102+112+122=447 and 447 mod 2 = 1
Sorry, the comment form is closed at this time.