#P3201. Pudding Color Segments Query
Pudding Color Segments Query
Pudding Color Segments Query
You are given \( n \) puddings arranged in a row, each having an integer color. You must perform \( m \) operations. In each operation, you are given two integers \( a \) and \( b \): first, change all puddings of color \( a \) into color \( b \), and then output the current number of contiguous segments of puddings that have the same color.
A contiguous segment is defined as a maximal subarray in which all elements are equal. For example, if the colors are \( [1, 2, 2, 1] \), there are 3 segments: \( [1], [2,2], [1] \).
inputFormat
The first line contains two integers \( n \) and \( m \) where \( n \) is the number of puddings and \( m \) is the number of operations.
The second line contains \( n \) space-separated integers representing the initial colors of the puddings.
Each of the next \( m \) lines contains two integers \( a \) and \( b \), indicating that all puddings with color \( a \) should be changed to color \( b \), followed by a query to count the segments.
outputFormat
For each operation, output a single integer on a new line representing the current number of contiguous color segments after the operation.
sample
4 3
1 2 2 1
1 3
2 3
3 1
3
1
1
</p>