Rausen loves cakes. One day, he bought $n$ cakes and the color of each cake is described as an integer in $\left[1,1000000\right]$. Rausen lines the cakes from left to right.
Before eating, rausen proceeds $q$ operations on cakes.
At one time point, rausen would replace all cakes of $x$ color with those of color $y$.
At another time point, rausen would calculate the number of segment colors in the interval$\left[x,y\right]$. A color segment is defined as an interval of one single color. For example,'1 4 4 1 1' involves 3 color segments.
Nevertheless, rausen finds that he cannot compile the statistics of color segments in the interval, which makes him weep like a helpless crybaby (bazinga). Please help rausen resolve the problem to placate him.