#SGM0000057. Gán đoạn và hợp thành hàm trên đoạn (Range Set Range Composite)
Gán đoạn và hợp thành hàm trên đoạn (Range Set Range Composite)
Range Set Range Composite
Source: Library Checker
Version: Phuoc Hung OJ Extended
Problem Statement
Maintain affine functions modulo . Type 0 sets every function in half-open range to the same affine function. Type 1 evaluates their ordered composition at .
Input
The first line contains . The next lines contain for . Each query is 0 l r c d (assign the same function to all indices in half-open range ) or 1 l r x (evaluate the ordered composition on ). Indices are 0-based.
Output
For each type-1 query print the composed value modulo .
Subtasks
-
Subtask 1 (20%): size and operation count at most 30; all other validity conditions are unchanged.
-
Subtask 2 (30%): size and operation count at most 3000; all other validity conditions are unchanged.
-
Subtask 3 (50%): full constraints:
-
-
-
Examples
Input
3 4
1 1
2 0
1 3
1 0 3 1
0 1 3 1 0
1 0 3 5
1 1 3 7
Output
7
6
7
Explanation
Composing the three initial functions at gives 7. After assigning the last two functions, the next two queries give 6 and 7.