| SVU-HIAST CPC 2025 |
|---|
| Finished |
Ammar and Ahmad decided to ask Obada to moderate a debate.
Ahmad (the affirmative team) is trying to prove that his algorithm "Matrix Bel Lotus" can solve any problem.
While Ammar (the opposing team) is going against his argument, Ammar needs your help.
Ahmad has some experience in debating, so Ammar needs to keep track of his debate tree and needs to know the lowest common ancestors of some nodes to support his arguments.
There are $$$n$$$ arguments in total, and the first argument is the main argument, while each other argument is either based on the main argument or another argument.
You will be given an array $$$a$$$ of $$$n$$$ elements, each element $$$a[i]$$$ which indicates that the argument number $$$i$$$ is based on the argument number $$$a[i]$$$.
Now, of course, Ahmad (an expert in debating) will try to juggle the arguments around and try to confuse Ammar by doing some updates on the array $$$a$$$, and occasionally Ammar will ask you some questions.
The first line contains $$$tc$$$ $$$(1 \leq tc \leq 100)$$$ — the number of test cases.
The first line of each test case contains two integers $$$n,q$$$ $$$(2 \leq n \leq 10^5)$$$ $$$(1 \leq q \leq 10^5)$$$ — the number of arguments and the number of queries.
The next line contains $$$n$$$ integers that represent the array $$$a$$$ $$$(1 \le a[i] \lt i)$$$ except for $$$a[1] = -1$$$.
The following $$$q$$$ lines will be one of the following:
It is guaranteed that the sum of $$$n$$$ over all testcases doesn't exceed $$$10^5$$$ , and the sum of $$$q$$$ over all testcases doesn't exceed $$$10^5$$$.
For each query of type $$$3$$$, print the answer.
111 5-1 1 1 2 2 3 3 4 4 5 53 8 102 7 10 23 10 61 10 113 11 5
2 3 2
Initially, the tree looks like this:
Then after the second query:
Then after the fourth query:
| Name |
|---|


