#P4458. [BJOI2018] 链上二次求和

    ID: 3385 远端评测题 4000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2018线段树各省省选北京枚举,暴力前缀和差分

[BJOI2018] 链上二次求和

Description

There is a chain of length nn (an undirected graph where 1i<n\forall 1 \leq i < n, there is an edge between node ii and node i+1i+1). Each node has an integer weight; the weight of the ii-th node is aia_i. There are mm operations, each as follows:

Operation 1 (modify): Given two nodes u,vu, v on the chain and an integer dd, add dd to the weight of every node on the unique simple path from uu to vv on the chain.

Operation 2 (query): Given two positive integers l,rl, r, compute the sum of node-weight sums over all simple paths whose number of nodes is at least ll and at most rr. Since the answer can be very large, output the result modulo the prime 10000000071000000007.

The node-weight sum of a simple path with kk nodes is the sum of the weights of all kk nodes (including endpoints) on that path. In this problem, you need to compute the sum of this value over all simple paths that meet the requirement.

Since the graph is undirected, paths are undirected as well; that is, the path from node 11 to node 22 is the same as the path from node 22 to node 11, so do not double count.

Input Format

The first line contains two positive integers n,mn, m, denoting the number of nodes and the number of operations.

The second line contains nn integers; the ii-th number aia_i is the initial weight of the ii-th node.

Each of the next mm lines is in the form 1 u v d or 2 l r, indicating an Operation 1 (modify) or Operation 2 (query), respectively.

Output Format

For each query, output one line with one integer, which is the answer modulo 10000000071000000007.

5 5
1 1 1 1 1
2 5 5
2 1 2
1 1 2 2
2 1 1
1 1 5 3
5
13
9

Hint

Sample Explanation:

There is exactly 11 simple path with 55 nodes, and its node-weight sum is 55, so the first query outputs 55.

There are 55 simple paths with 11 node, each with node-weight sum 11; there are 44 simple paths with 22 nodes, each with node-weight sum 22, so the second query outputs 1313.

After adding 22 to the weights of nodes 11 and 22, the 55 simple paths with 11 node have node-weight sums 33, 33, 11, 11, 11, so the third query outputs 99.

Constraints:

Let the number of Operation 1 (modify) be mm^\prime.

For all testdata, it is guaranteed that n200000n \leq 200000, m500000m \leq 500000, m100000m^\prime \leq 100000, 0ai<10000000070 \leq a_i < 1000000007.

1un1 \leq u \leq n, 1vn1 \leq v \leq n, 0d<10000000070 \leq d < 1000000007, lrnl \leq r \leq n.

For the detailed scale and conventions of each test point, see the table below.

pic

Translated by ChatGPT 5