← All problemsSign in

Sereja and Inversions

CodeChefRating 2873Open on judge ↗

Sereja has a permutation P of the N numbers in the range 1 to N. You have to answer M queries over it, where each query is given four numbers l1, r1, l2, r2 (1 ≤ l1 ≤ r1 2 ≤ r2 ≤ N, r1 - l1 = r2 - l2). Your task is to calculate number of permutations Q of the S integers in the range 1 to S, such that S = r1 - l1 + 1, and for each i from 1 to S, the condition PQi + l1 - 1 i + l2 - 1 is satisfied.

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