PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FT0000250. Biến đổi affine và tính tổng đoạn (Range Affine Range Sum)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Biến đổi affine và tính tổng đoạn (Range Affine Range Sum)
Range Affine Range Sum
Source: Library Checker
Version: Phuoc Hung OJ Extended
Problem Statement
You are given the array . Values are considered modulo . Process operations in order:
0 l r b c: for every , replace with .1 l r: print .
Successive transformations must be applied in input order.
Input
- The first line contains .
- The second line contains values .
- The next lines contain operations
0 l r b cor1 l r.
Output
For each type 1 operation, print the corresponding sum modulo on a separate line.
Subtasks
-
Subtask 1 (20 points): ; ; ; ; .
-
Subtask 2 (30 points): ; ; ; ; .
-
Subtask 3 (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 initial sum is . The first update changes to and to , so the next sum is . The second update changes from to and from to ; therefore the sum over is . The final update changes to , to , and to . The final full-array sum is .