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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 artificial intelligence with max(ai−x,1) for all I with l≤i≤r. 

 

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

 

 

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Types of trees
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education