← All problemsSign in

Chefina and Beautiful Pairs

You are given a sequence $A_1, A_2, \ldots, A_N$. A pair of indices $(i,j)$ in an array $A$ is called **Beautiful Pair** if $i \neq j$ and $A[i] = A[j]$. The strength of a beautiful pair $(i,j)$ is $|i-j|$. You are given $q$ queries each having two integers $l$ and $r$. For each query, print the sum of the strength of all beautiful pairs in the subarray of $A$ ranging from $l$ to $r$(inclusive

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