Editorial
Fix the left endpoint , and extend the right endpoint from to one by one.
Maintain the occurrence counts of values inside the current interval. When is added, we can check whether this value was absent before. If so, the number of distinct integers increases by .
The interval length is , so we compute for every interval and update the maximum.
There are intervals, and each update can be done in expected time. Therefore, the total time complexity is .