#P3348. Forest Growth Management
Forest Growth Management
Forest Growth Management
In this problem, you are given a forest with \(n\) trees numbered from \(1\) to \(n\). Initially, each tree consists of a single node with label \(1\), which is also its growth node. A growth node is a special node that can produce a new child.
You need to process \(Q\) operations. There are three types of operations:
- Growth Operation: Given integers
1 l r
. For every tree with index in \([l, r]\), let its current growth node produce a new child. The new child's label is defined as the current maximum label of that tree plus one. After adding the child, update the growth node to this new node. - Modification Operation: Given integers
2 l r x
. For every tree with index in \([l, r]\), if a node with label \(x\) exists in that tree (i.e. if \(x\) is less than or equal to the current maximum label in that tree), then update the growth node to be the node with label \(x\). Otherwise, ignore the operation for that tree. - Query Operation: Given integers
3 i
. Output the label of the current growth node of the \(i\)th tree.
Input Format:
- The first line contains two integers \(n\) and \(Q\).
- Each of the following \(Q\) lines describes an operation in one of the following formats:
1 l r
— a growth operation.2 l r x
— a modification operation.3 i
— a query operation.
Output Format:
- For each query operation, output the respective result on a separate line.
Your task is to simulate the operations and answer all the queries.
inputFormat
The input begins with a line containing two integers \(n\) and \(Q\), representing the number of trees and the number of operations, respectively.
Each of the next \(Q\) lines contains an operation in one of the following formats:
1 l r
— Growth operation.2 l r x
— Modification operation.3 i
— Query operation.
outputFormat
For each query operation (of the form 3 i
), output the label of the current growth node of the \(i\)th tree on a new line.
sample
3 5
1 1 2
3 1
2 1 3 1
3 2
3 3
2
1
1
</p>