← All problemsSign in

Double or Append

CodeChefRating 1812Open on judge ↗

You start off with initially array $A = [0]$. You need to handle $M$ operations of $2$ types: - $T_i = 1$ : Let $X = \operatorname{MEX}(A)$ $^{\dagger}$, replace $A$ with $[X] + A$. - $T_i = 2$ : Replace $A$ with $A + A$. In both the above cases, $+$ denotes array concatenation. After each operation, find the number of inversions$^{\ddagger}$ in the array $A$. It is guaranteed that the length

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.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start