#K64677. Waterfall Valve Operations Simulation
Waterfall Valve Operations Simulation
Waterfall Valve Operations Simulation
You are given a vertical waterfall network consisting of n pipelines aligned from top to bottom. Each pipeline has a valve that can be opened. Initially, only the bottom-most pipeline (indexed by n) is wet because its valve is permanently open. You will be provided with a series of operations that open the valves of specific pipelines. For each operation, open the valve at the given pipeline and then report all the pipelines that become wet. The pipelines that are wet are the ones whose valves have been opened up to that point. The order of the pipelines in your output should be in ascending order.
More formally, let \( n \) be the number of pipelines and let \( m \) be the number of operations. Initially, the set of wet pipelines is \( \{ n \} \). For each operation, you add the valve index \( op_i \) to the set. After each operation, output the sorted list of wet pipelines.
Note: All formulas are represented in LaTeX format. For instance, the number of wet pipelines after each step is determined by the equation \( W_i = \{ op_1, op_2, \ldots, op_i \} \cup \{ n \} \) where the union is taken over the operations performed so far.
inputFormat
The input is given via standard input (stdin) in the following format:
- The first line contains two integers
n
andm
wheren
is the number of pipelines andm
is the number of operations. - The second line contains
m
space-separated integers, representing the sequence of pipeline indices whose valves are opened in the given order.
outputFormat
For each operation, output a single line containing the indices of the wet pipelines in ascending order, separated by a single space. The output should be printed to standard output (stdout).
## sample5 5
3 4 1 2 5
3 5
3 4 5
1 3 4 5
1 2 3 4 5
1 2 3 4 5
</p>