#SGM0000040. Biến đổi affine và tổng đoạn (Range Affine Range Sum)
Biến đổi affine và tổng đoạn (Range Affine Range Sum)
Range Affine Range Sum
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Apply affine maps on half-open ranges and query range sums modulo .
Input
The first line contains and the next line . Queries are:
0 l r b c: for , set modulo .1 l r: print modulo .
Output
Print one line for every type 1 query.
Subtasks
- 20 points: .
- 30 points: .
- 50 points: , , .
Examples
Input
5 7
1 2 3 4 5
1 0 5
0 2 4 100 101
1 0 3
0 1 3 102 103
1 2 5
0 2 5 104 105
1 0 5
Output
15
404
41511
4317767
Explanation
The first answer is 15. Each update applies an affine function in chronological order, with arithmetic modulo . The later answers are 404, 41511, and 4317767.