Primal Collection
Time limit1sMemory limit2048 MB
Count the primal arrays over values 1 to N+1 (missing S) for which inserting S at position N+1 and sifting it up takes exactly K swaps.
- Level
Hard8 of 10
- Topics
- Combinatorics, Tree, Dynamic programming
- Solved
- No attempts yet
Problem
You are given an array , which initially has a size of (indexed from to ) containing distinct integers with values between and inclusive. It is known that this array is primal, that is, for any index , is always smaller than .
Denote as the value between and that does not appear in . You want to append one new element to , namely , with the value . Then the following algorithm is executed.
algorithm(A):
x = N + 1
counter = 0
while x > 1:
if A[x] > A[floor(x / 2)]:
swap(A[x], A[floor(x / 2)]);
counter = counter + 1
x = floor(x / 2)
return counter
Count the number of possible initial arrays such that, after appending and executing algorithm(A), the algorithm returns . The initial array contains distinct integers with values between and inclusive, excluding , and must be primal. Since the answer can be very large, print it modulo .
Input
A single line with three integers , , (; ; ).
Output
A single integer, the number of possible initial arrays that satisfy the conditions above, modulo .