← All problemsSign in

Permutation Pairs

CodeChefRating 2721Open on judge ↗

For an integer $K$ and a permutation $A = [A_1, A_2, \dots, A_N]$ of values from $1$ to $N$, we define a function $f(A)$ that returns the number of pairs of integers $(i, j)$ such that - $1 \le i \lt j \le N$ - $j \gt i+K$ - $A_j \gt A_i$ - For all $x \geq (i+1)$ and $x\leq(j-1)$ , $A_x \lt A_i$ - for all $x \lt i$ , $A_x \lt A_i$ In simple words, in the subarray $A_{[1..j]}$, $A_i$ is the second

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