QOJ.ac

QOJ

时间限制: 3 s 内存限制: 500 MB 总分: 100

#7471. ODT

统计

You are given a tree where each edge has a weight of $1$ and each node has a weight.

You need to support two types of operations:

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

Input

The first line contains two integers $n$ and $m$.

The second line contains $n$ integers representing the initial weights of the nodes.

The next $n-1$ lines each contain two integers $x$ and $y$, representing an edge between $x$ and $y$.

The following $m$ lines each contain an operation in the format 1 x y z or 2 x y, as described above.

Output

For each type 2 operation, output one integer per line representing the answer.

It is guaranteed that an answer exists for every query.

Examples

Input 1

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

Output 1

4
3
4

Note

Idea: nzhtl1477

Solution: nzhtl1477 ($O( n\log^2n/ \log\log n )$ solution), negiizhao ($O( n\log n\log\log\log n )$ solution), ccz181078 ($O( n\log n )$ solution)

Code: nzhtl1477 ($O( n\log^2 n/ \log\log n )$ code)

Data: nzhtl1477 (partially uploaded)

  • Subtask 1: $20\%$, $n,m\leq 1000$.
  • Subtask 2: $10\%$, the tree is a chain.
  • Subtask 3: $20\%$, $n,m\leq 10^5$.
  • Subtask 4: $30\%$, $n,m\leq 4\times 10^5$.
  • Subtask 5: $20\%$, $n,m\leq 10^6$.

For $100\%$ of the data, $1\leq n,m\leq 10^6$, $0\leq$ value added in each operation $\leq 2000$, $0\leq$ initial node weights $\leq 2000$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.