#P3178. [HAOI2015] 树上操作

    ID: 2227 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2015河南线段树深度优先搜索,DFS树链剖分,树剖

[HAOI2015] 树上操作

Description

There is a tree with NN nodes, rooted at node 11, and each node has a weight. There are MM operations of three types:

  • Operation 11: increase the weight of node xx by aa.
  • Operation 22: increase the weight of every node in the subtree rooted at node xx by aa.
  • Operation 33: query the sum of weights of all nodes on the path from node xx to the root.

Input Format

The first line contains two integers N,MN, M, representing the number of nodes and the number of operations.
The next line contains NN integers, representing the initial weights of the nodes.
Each of the next N1N-1 lines contains two positive integers from,to\mathit{from}, \mathit{to}, indicating that there is an edge (from,to)(\mathit{from}, \mathit{to}) in the tree.
Then there are MM lines, each describing one operation. The first number indicates the type of the operation, followed by the parameters of that operation.

Output Format

For each query operation, output the answer. Print each answer on a new line.

5 5
1 2 3 4 5
1 2
1 4
2 3
2 5
3 3
1 2 1
3 5
2 1 2
3 3
6
9
13

Hint

For 100%100\% of the testdata, 1N,M1051 \le N, M \le 10^5, and the absolute values of all input numbers do not exceed 10610^6.

Translated by ChatGPT 5