Let's say we have given array of $n$ elements, now we want to create data structure that will allow us to get the MEX of its elements, MEX meaning the smallest positive integer that is not present in the set. More info from wikipedia. The data structure should also support insert and remove elements from itself.
In other words, we have given multiset with $n$ elements, we want to find MEX of itself, but we should support removing and adding elements.
What I was thinking was that we should first process the elements on some way, and then when adding new element in the set we should check if it is equal to the MEX, but there are many cases to worry about, so I couldn't come to complete solution.
The data structure should support both the queries/updates in $O(logN)$ or similar time complexity classes.