← All problemsSign in

Subarray Weight

CodeChefRating 2645Open on judge ↗

You are given a [permutation](https://en.wikipedia.org/wiki/Permutation) $P$ of $N$ integers from $1$ to $N$. The *weight* of a subarray $[L, R]$ $(1\le L \le R \le N)$ is defined as $|i - j|$ where $i$ denotes the index of the **maximum** element and $j$ denotes the index of the **minimum** element in the subarray $[L,R]$. Find the **sum** of the *weights* of **all** subarrays of the given pe

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