Since the maximum size of each section in a complete range of static asking segment
Mo looks like a very good team with a transfer, so consider how transfer
When it extended to a number, it is to add a value range
This value may already exist, it could be new
Some gods approach is to maintain a disjoint-set, but I force this code ..
So I used a more primary operation for each successive point marked the farthest left and farthest right continuous mark
When you add a new point, while continuously updates its furthest to the left and right values farthest continuous label
This is to add, delete it
For now, if the state before the point of impact of each and all of its subsequent impact and its impact is not recorded, even if deletion wilt
So try not to delete
Mo can know the nature of a team has, in the same sub-block in the left point, right point is monotone
Although not monotonic left point, but their range is limited in a small interval (block N's root)
And for each point of the left block, run again O (N) operations are no problem
If you want to add, I do not want to delete words ..
Each time the count put another empty block, the left and right end on the right end of the block, the recording state in this state
Every time the right to expand, update state
After each expand to the left, records state before expansion, expand restore state
This ensures that there is left up to each inquiry record N th root complexity and recovery
Each block has at most a O (N) emptied
Complexity becomes O (N√N).