Problem link : https://toph.co/p/unbelievable-array How should I approach this problem? Someone help please.
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Problem link : https://toph.co/p/unbelievable-array How should I approach this problem? Someone help please.
Name |
---|
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 !
Let's see how can we apply disjoint set here.
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].