#P1276. Tree Plantation and Cutting Simulation
Tree Plantation and Cutting Simulation
Tree Plantation and Cutting Simulation
There is a row of trees located along the road just outside the school gate, with positions numbered from \(0\) to \(L\) (inclusive). Each position initially has a mature tree. Two types of operations will be performed sequentially:
- Lumberjack Operation: Denoted by
0 A B
where \(0 \leq A \leq B \leq L\). In this operation, every tree (or seedling) at positions \(A\) through \(B\) (inclusive) is cut down completely. - Planter Operation: Denoted by
1 C D
where \(0 \leq C \leq D \leq L\). In this operation, at every position from \(C\) to \(D\) (inclusive) that is empty (i.e. the tree has been cut and there is no replanting currently), a seedling is planted.
Your task is to determine two numbers after all operations have been executed:
- The total number of seedlings remaining (seedlings that were planted and never subsequently cut).
- The number of seedlings that were planted and then later cut by a lumberjack operation. </p>
0 A B
: The lumberjack operation, cutting all trees (or seedlings) in the interval \([A, B]\).1 C D
: The planter operation, planting a seedling at each empty position in the interval \([C, D]\).- The number of seedlings remaining after all operations.
- The number of seedlings that were planted by a planter operation and later cut by a lumberjack operation.
Note: Initially every position (from \(0\) to \(L\)) contains a mature tree. When a lumberjack operation is performed, if a seedling is cut, it will be counted toward the second number. Cutting a mature tree does not count.
inputFormat
The first line contains two integers \(L\) and \(Q\) where \(L\) (\(0 \leq L \leq 10^5\)) is the maximum index and \(Q\) is the number of operations.
Each of the following \(Q\) lines contains an operation in one of the following formats:
outputFormat
Output two integers separated by a space:
sample
5 3
0 1 3
1 2 4
0 3 5
1 1