This problem can be easily solvable by using Merge Sort Tree. If you are hearing this name for the first time, you can learn it from plenty of online resources, one of them is here.

So, I am assuming that you know MST or you just learned it now.

Let, $ query(L, R, val) $ is the query function of the MST which returns the total number of values less than or equal to $ val $ in range $ L $ to $ R $ of an array. Now, we can get the total number of affect value between $ P $ to $ Q $ by:

$ query(L, R, Q) - query(L, R, P - 1) $

Then, if the answer is non-zero, we need to find the minimum and maximum
affect value. Which can be found by performing binary search on the vectors while working with query function of Merge Sort Tree.

Statistics

69% Solution Ratio
prodip_bsmrstuEarliest, Sep '19
mdshadeshFastest, 0.0s
mdshadeshLightest, 24 kB
SoudipShortest, 1398B
Toph uses cookies. By continuing you agree to our Cookie Policy.