Yuezheng Ling gives Luo Tianyi a tree which has n hubs, established at 1. Luo Tianyi will let you know that the parent of the I-th hub is simulated intelligence (1≤ai
Correct answer will be upvoted else downvoted. Computer science.
Yuezheng Ling gives Luo Tianyi a tree which has n hubs, established at 1.
Luo Tianyi will let you know that the parent of the I-th hub is simulated intelligence (1≤ai<i for 2≤i≤n), and she will request that you perform q questions of 2 sorts:
She'll give you three integers l, r and x (2≤l≤r≤n, 1≤x≤105). You want to supplant man-made intelligence with max(ai−x,1) for all I with l≤i≤r.
She'll give both of you integers u, v (1≤u,v≤n). You want to find the LCA of hubs u and v (their most minimal normal progenitor).
Input
The primary line contains two integers n and q (2≤n,q≤105) — the number of hubs and the number of inquiries, individually.
The subsequent line contains n−1 integers a2,a3,… ,an (1≤ai<i), where simulated intelligence is the parent of the hub I.
Next q lines contain inquiries. For each question, the main integer of each line is t (t=1 or 2) — the kind of the inquiry.
If t=1, this addresses the inquiry of the main kind. Then, at that point, three integers will follow: l, r, x (2≤l≤r≤n, 1≤x≤105), implying that you need to supplant
In the event that t=2, this addresses the question of the subsequent sort. Then, at that point, two integers will follow: u and v (1≤u,v≤n), and you need to find the LCA of u and v.
It's dependable that there is somewhere around one question of the subsequent sort.
Output
For each question of the subsequent sort output reply on another line
Step by step
Solved in 3 steps with 1 images