#P3700. [CQOI2017] 小 Q 的表格

    ID: 1273 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学2017重庆各省省选枚举,暴力前缀和

[CQOI2017] 小 Q 的表格

Description

Xiao Q is a programmer.

As a young programmer, Xiao Q is always bullied by old C, who often assigns him troublesome tasks. Whenever Xiao Q does not know how to solve them, he has to ask you for help.

To complete the task, Xiao Q needs to make a table with infinitely many rows and infinitely many columns, both indexed starting from 11. Every cell in the table contains an integer. For convenience, Xiao Q denotes the integer in row aa, column bb as f(a,b)f(a, b). The table must satisfy the following conditions:

  1. For any positive integers a,ba, b, it must hold that f(a,b)=f(b,a)f(a, b) = f(b, a).
  2. For any positive integers a,ba, b, it must hold that b×f(a,a+b)=(a+b)×f(a,b)b \times f(a, a + b) = (a + b) \times f(a, b).

Initially, the numbers in the table are very regular: the number in row aa, column bb is exactly a×ba \times b, which obviously satisfies the two conditions above. To complete the task, Xiao Q will keep modifying the numbers in the table. Each time a cell is changed, in order to keep the table satisfying the two conditions, Xiao Q must also update all cells that can be affected by this modification to appropriate values. By some mysterious power, it is guaranteed that after each round of modification all entries remain integers. Xiao Q also needs to query, at any time, the sum of all numbers in the finite region of the first kk rows and first kk columns; since the answer may be large, it suffices to output the result mod1,000,000,007{} \bmod 1,000,000,007.

Input Format

The first line contains two integers m,nm, n, indicating that there are mm operations, and that all row and column indices mentioned in the operations and queries do not exceed nn.

Then follow mm lines, each containing four integers a,b,x,ka, b, x, k, meaning: set the number in row aa, column bb to xx, then update all cells that can be affected by this change, with the guarantee that after the modification all entries are still integers. After the modification is completed, compute the sum of all numbers in the first kk rows and first kk columns.

Output Format

Output mm lines. After each operation, output one line containing the answer modulo 1,000,000,0071,000,000,007.

3 3
1 1 1 2
2 2 4 3
1 2 4 2

9
36
14

4 125
1 2 4 8
1 3 9 27
1 4 16 64
1 5 25 125

2073
316642
12157159
213336861

Hint

Sample Explanation #1

Initially, the top-left 3×33 \times 3 submatrix is as shown on the left. There is no change after the first 22 operations. After the 33rd operation, the table becomes as shown on the right.

1 2 3     2  4  6
2 4 6     4  4 12
3 6 9     6 12  9

Constraints

For 100%100\% of the testdata, 1m1041 \le m \le 10^4, 1a,b,kn4×1061 \le a, b, k \le n \le 4 \times 10^6, 0x10180 \le x \le 10^{18}.

Translated by ChatGPT 5