#FT0000021. Tổng tiền tố ba lần (Cumulative Cumulative Cumulative Sum)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tổng tiền tố ba lần (Cumulative Cumulative Cumulative Sum)
Cumulative Cumulative Cumulative Sum
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a sequence of nonnegative integers . From , define three cumulatively summed sequences , for every :
$$B_i=\sum_{j=1}^{i}A_j,\qquad C_i=\sum_{j=1}^{i}B_j,\qquad D_i=\sum_{j=1}^{i}C_j.$$Process commands in order. Command 1 x v replaces with . Command 2 x asks for computed from the current array , and prints modulo .
After an assignment, are understood to be redefined from the updated . All three prefix summations begin at index . A query does not modify .
Input
- Line 1:
n qgives array length and command count. - Line 2:
A_1 A_2 ... A_ngives the initial values in index order. - Next lines: each line contains one of the following commands, in execution order:
1 x v: set .2 x: query .
Output
For every 2 x command, print as one integer in , on a separate line.
Subtasks
Subtask 1 (20 points):
- .
- .
- .
- .
- query modulus is .
Subtask 2 (30 points):
- .
- .
- .
- .
- query modulus is .
Subtask 3 (50 points):
- .
- .
- .
- .
- query modulus is .
Examples
Input
3 3
1 2 3
2 3
1 2 0
2 3
Output
15
9
Explanation
Initially . All sequences use 1-based indices.
-
2 3: the first prefix sums are . The next are . Finally . Thus , unchanged modulo ; print15. -
1 2 0: assign the second element of to , replacing its old value . Now . -
2 3: recompute the cumulative sequences from the updated : , , . Therefore print9. The earlier result no longer applies after the assignment.