Problem link : https://toph.co/p/unbelievable-array How should I approach this problem? Someone help please.
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 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].