I observed that in every case , mex will be equal to that of whole array . Then we can use dp , binary search and mex range query to solve the problem. complexity O(nlognlogn).
Is this approach correct ?
I found how to calculate mex range query very late thus it was too late to code.
Please share other approaches too.