Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official. ×

### Hunter_Gon's blog

By Hunter_Gon, history, 6 months ago, ,

Problem link : https://toph.co/p/unbelievable-array How should I approach this problem? Someone help please.

 » 6 months ago, # |   0 First,hash all the indexes with same values with distinct integers i.e, if the given array is 1 2 3 2 1 4 2 1 , indexes 1,5,8 will be hashed to 1 , indexe(s) 2,4,7 will be hashed to 2, indexe(s) 3 will be hashed to 3 , indexe(s) 6 will be hashed to 4 and also store their corresponding values ! Now if you want to change index x in the original array to some y , go to the hashed index of x and update its value to y and if you want to query the index x in the original array , go to the hashed index of x and print its value ! I have not submitted the solution for this , just an idea ! My first comment on CF ! Please ignore if there are any mistakes !
 » 6 months ago, # |   +8 Let's see how can we apply disjoint set here. while scanning the input array if a value already occurred then we just merge both the index and update the leader of this group with value y for query 1 x y while performing A[idx] we need to find the leader of idx, and then we get the stored value corresponding to that leader. I made a submission here here. Let me know if you have any questions.
•  » » 6 months ago, # ^ |   0 I can't see the code, can you please give me your code through pastebin?
•  » » » 6 months ago, # ^ |   0 You need to login to see, anyways you can see here.
 » 6 months ago, # |   0 First initialize the parents of each number from 1 to 100000.For type 1 operation set the parent of x as y.For type 2 operation print the parent of a[idx].