#C10778. Sequence Transformation Using Replacement Operations
Sequence Transformation Using Replacement Operations
Sequence Transformation Using Replacement Operations
You are given a sequence of integers of length \( n \). Additionally, you are provided with \( m \) replacement operations. Each operation is a tuple \( (x, y) \) which means: find the first occurrence of \( x \) in the sequence, replace it with \( y \), and continue this replacement until there are no more occurrences of \( x \) left. You then move to the next operation and repeat the process. This whole procedure is repeated until no further replacements can be performed.
The objective is to output the final sequence after all possible transformations have been applied.
Note: The operations are applied in the given order, and within each operation, only the first occurrence is replaced at a time, followed by another check for \( x \) before moving to the next operation.
inputFormat
The input is given as follows:
- The first line contains an integer \( n \) representing the length of the sequence.
- The second line contains \( n \) integers, which constitute the sequence.
- The third line contains an integer \( m \) denoting the number of operations.
- Each of the following \( m \) lines contains two integers \( x \) and \( y \), representing an operation: replace the first occurrence of \( x \) with \( y \) repeatedly until no further replacement is possible.
outputFormat
Output the final sequence after performing all the operations. The sequence should be printed as a sequence of space-separated integers on a single line.
## sample5
1 2 2 3 4
3
2 3
3 1
4 0
1 1 1 1 0