[Solved] Problem Link: https://toph.co/p/unbelievable-array
My solution: https://ideone.com/USMnVT
Verdict: Wrong Answer
My approach: For all the same numbers I am trying to group them using disjoint set data structure. I am referring the value of the numbers in each of the index of the array A as color. So, each of the distinct colors will have a distinct parent. I am mapping the color to the parent using color array. Also, I am mapping the parent to the color using par array. So, for queries which need replacing one color by other there are two cases where I need to change the value in the color and par array, one is when both the colors are present and another, the color to be replaced by is not present but the color which will get replaced is present in the array. And for the query which asks for the color value in the index idx I am finding it's parent and then displaying the result from the parent to color mapping array (**par**).
Can anyone please help me in finding why I am getting WA? Thanks in advance.
What happens when you have a query of the form 1 x x?
Oops, missed out this condition. Thanks a ton. Got AC.