Do Not Touch the MEX!!!
Utkarsh has a [permutation](https://en.wikipedia.org/wiki/Permutation) $P$ of $\{0, 1, 2, \dots, N-1\}$. He wants to find the number of pairs $(L, R)$ $(1 \leq L \lt R \leq N)$ such that swapping the elements $P_L$ and $P_R$ does not change the [MEX](https://en.wikipedia.org/wiki/Mex_(mathematics)) of any [subarray](https://stackoverflow.com/a/45686639). Formally, find the number of pairs $(L, R
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start