#P5314. [Ynoi2011] ODT

[Ynoi2011] ODT

Description

You are given a tree where each edge has weight 11, and each node has a weight.

Support two operations:

  • 1 x y z: Add zz to the weights of all nodes on the simple path from xx to yy.
  • 2 x y: Query the yy-th smallest node weight among all nodes whose distance to node xx is less than or equal to 11.

Input Format

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

The second line contains nn integers, the weight of each node.

Then follow n1n-1 lines, each containing two integers x,yx, y indicating that there is an edge between xx and yy.

Then follow mm lines, each in the form 1 x y z or 2 x y, as described above.

Output Format

For each operation of type 22, output one line with one integer, the answer.

It is guaranteed that the answer exists for every query.

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

4
3
4

Hint

  • Idea: nzhtl1477.
  • Solution: nzhtl1477 ( O(nlog2n/loglogn)O( n\log^2 n / \log\log n ) solution ), negiizhao ( O(nlognlogloglogn)O( n\log n\log\log\log n ) solution ), ccz181078 ( O(nlogn)O( n\log n ) solution ).
  • Code: nzhtl1477 ( O(nlog2n/loglogn)O( n\log^2 n / \log\log n ) code ).
  • Data: nzhtl1477 ( partially uploaded ).

Subtask 1: 20%20\% n,m1000n, m \leq 1000.

Subtask 2: 10%10\% the tree is a chain.

Subtask 3: 20%20\% n,m105n, m \leq 10^5.

Subtask 4: 30%30\% n,m4×105n, m \leq 4\times 10^5.

Subtask 5: 20%20\% n,m106n, m \leq 10^6.

Constraints: For 100%100\% of the testdata, 1n,m1061 \leq n, m \leq 10^6, 00 \leq the value added in each update 2000\leq 2000, 00 \leq the initial node weights 2000\leq 2000.

Translated by ChatGPT 5