Help in codeforces Problem C-Destroying Array

I am not able to solve this problem.
I tried to understand the editorial.
I didn’t understand how can we use stl set to find the nearest to the left and to the right destroyed number.

Also, if there is another approach please explain to me.

Problem Link

Editorial

//