## 03 Jun PMCA Friday 19:00 Python Homework 20.05.29.

Question:

Rory is playing with an array ** A** consisting of

*integer elements indexed from 1 to*

**N***and a positive integer*

**N***. Rory will perform*

**M****operations. Each operation is either type 1 or type 2.**

*Q*Type 1 operation is in the form ** 1 l r x**. You should add

**to each element in**

*x**A[l], A[l + 1], …, A[r]*.

Type 2 operation is in the form ** 2 l r**. You should output the sum (A[l]

*+ A[l + 1]*

^{M}*+ … + A[r]*

^{M}*) mod*

^{M}*(MOD is calculate remainder of division, it is % in python).*

**M****Input Specification**

The first line of input will contain three integers ** M**,

**, and**

*N***.**

*Q*The second line of input will contain

**elements, the original elements of array**

*N**in the order*

**A***A[1], A[2], …, A[N]*.

The next

*lines of input will contain an operation, either in the form*

**Q****for an operation of type 1 or**

*1 l r x***for an operation of type 2.**

*2 l r***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, 1* ^{2}*+2

*+3*

^{2}*+4*

^{2}*=30, and 30 mod 2 = 0.*

^{2}For the second operation, the array

**is now 1, 9, 10, 11, 12.**

*A*For the third operation, 1

*+9*

^{2}*+10*

^{2}*+11*

^{2}*+12*

^{2}*=447 and 447 mod 2 = 1*

^{2}
Sorry, the comment form is closed at this time.