← All problemsSign in

Minimum and Maximum

CodeChefRating 2875Open on judge ↗

Chef has a $permutation$ $P_1, P_2, \ldots, P_N$ of integers $1$ through $N$. He needs you to find the value of the sum $$S = \sum\limits_{i=1}^{N} \sum\limits_{j=i}^{N} \mathrm{getMin}\,(i, j) \; \wedge \; \mathrm{getMax}\,(i, j) \,,$$ where $\wedge$ denotes the bitwise AND operation and $$\mathrm{getMin}\,(i, j) = \mathrm{min}\,(P_i, P_{i+1}, \ldots, P_{j-1}, P_j) \,,$$ $$\mathrm{getMax}\,(i, j)

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