#P13567. 「CZOI-R5」折跃点

    ID: 14401 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>线段树树状数组洛谷原创O2优化广度优先搜索 BFS洛谷比赛

「CZOI-R5」折跃点

Background

An interstellar war has broken out in the universe.

Problem Description

To perform instant movement in the interstellar war, we have built nn warp points in the occupied star regions. All warp points form a rooted tree with warp point 11 as the root. The energy value of warp point ii is aia_i.

We say that warp point uu can reach warp point vv after xx consecutive warps if and only if starting from warp point uu, after walking along xx edges we can arrive at warp point vv, and during the process the distance to warp point 11 keeps strictly increasing or keeps strictly decreasing.

Now we need to perform mm maintenance operations of the following types:

  1. Space Energy Boost: For all warp points that can be reached from warp point uu after xx consecutive warps, add yy to their energy values.
  2. Warp Test: For all warp points that can be reached from warp point uu after xx consecutive warps, output the sum of their energy values.

Input Format

The first line contains 22 integers n,mn, m.

The second line contains nn integers; the ii-th one is aia_i.

The next n1n - 1 lines each contain 22 integers u,vu, v, representing an edge.

The next mm lines each start with an integer pp, then:

  • If p=1p=1, input 33 integers u,x,yu, x, y, representing one Space Energy Boost.
  • If p=2p=2, input 22 integers u,xu, x, representing one Warp Test.

Output Format

Output several lines of integers, which are the results of all Warp Tests.

5 5
6 8 4 10 6 
2 1
3 2
4 1
5 4
1 1 2 7
2 4 1
2 2 0
1 2 1 4
2 1 2

19
8
28

Hint

Sample Explanation

The tree is shown in the figure.

In the first operation, the warp points that satisfy the condition are warp points 3,53, 5. After the operation, a={6,8,11,10,13}a=\{6,8,11,10,13\}.

In the second operation, the warp points that satisfy the condition are warp points 1,51, 5, and the answer is 6+13=196+13=19.

In the third operation, the warp point that satisfies the condition is warp point 22, and the answer is 88.

In the fourth operation, the warp points that satisfy the condition are warp points 1,31, 3. After the operation, a={10,8,15,10,13}a=\{10,8,15,10,13\}.

In the fifth operation, the warp points that satisfy the condition are warp points 3,53, 5, and the answer is 15+13=2815+13=28.

Constraints

This problem uses bundled testdata.

  • Subtask #1 (15 pts15\text{ pts}): n,m103n, m \le 10^3.
  • Subtask #2 (15 pts15\text{ pts}): x1x \le 1.
  • Subtask #3 (25 pts25\text{ pts}): x50x \le 50.
  • Subtask #4 (45 pts45\text{ pts}): No special constraints.

For 100%100\% of the testdata, 1un3×1051\le u\le n\le3\times10^5, 1m3×1051 \le m \le 3 \times 10^5, 1ai,y1091 \le a_i, y \le 10^9, 0xn0 \le x \le n, p{1,2}p\in\{1,2\}

Translated by ChatGPT 5