guide of the maze shapes a tree with n rooms numbered from 1 to n and n−1 burrows associating them to such an extent that it is feasible to go between each pair of rooms through a few passages. The I-th room (1≤i≤n) has simulated intelligence hallucination rate. To go from the x-th space to the y-th room, there should exist a passage among x and y, and it takes max(|ax+ay|,|ax−ay|) energy. |z| means the outright
Correct answer only. Else i will dislike.
The guide of the maze shapes a tree with n rooms numbered from 1 to n and n−1 burrows associating them to such an extent that it is feasible to go between each pair of rooms through a few passages. The I-th room (1≤i≤n) has simulated intelligence hallucination rate. To go from the x-th space to the y-th room, there should exist a passage among x and y, and it takes max(|ax+ay|,|ax−ay|) energy. |z| means the outright worth of z. To forestall grave looters, the labyrinth can change the hallucination pace of any room in it. Chanek and Indiana would ask q inquiries. There are two kinds of inquiries to be finished: 1 u c — The figment pace of the x-th room is changed to c (1≤u≤n, 0≤|c|≤109). 2 u v — Chanek and Indiana ask you the base amount of energy expected to take the mysterious fortune at room v in case they are at first at room u (1≤u,v≤n). Help them, so you can get a part of the fortune!
Input :The primary line contains two integers n and q (2≤n≤105, 1≤q≤105) — the number of rooms in the labyrinth and the number of inquiries. The subsequent line contains n integers a1,a2,… ,an (0≤|
Output :For each sort 2 question, output a line containing an integer — the base amount of energy required for Chanek and Indiana to take the mysterious fortune.
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 5 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)