Lava Jump 2
Time limit2sMemory limit512 MB
Count the ordered jump sequences, where each jump is at least twice the previous distance, that leave exactly one platform, after the initial setup and after each position change.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Divide and conquer, Sorting
- Solved
- No attempts yet
Problem
The study room at Gyeonggi Science High School sometimes fills with lava. Floating on the lava floor are platforms, numbered 1 through . The position of platform is the integer , and all positions are distinct. That is, for all integers , with . The lava floor cannot be stepped on, only the platforms can. Unfortunately, once a platform is stepped on, it sinks below the lava forever as soon as the foot leaves it, and it can never be stepped on again.
Jeonghu wants to know how many ways his friend Ihwan can start from each platform, make zero or more jumps, and end on exactly one platform while every other platform has sunk. However, Ihwan jumps too far. Once he has jumped a distance , every later jump must be at least . At first, he can jump any distance.
A jump from platform to platform has distance . Two ways are different if the order in which the platforms sink is different. Platforms that are not stepped on do not sink. Position changes accumulate.
Input
The first line contains two integers and , the number of platforms and the number of queries.
The second line contains integers separated by spaces. The -th integer is , the position of platform .
Each of the next lines contains two integers and , meaning platform moves to position .
Output
On the first line, print the number of ways modulo in which Ihwan, starting from some platform, makes zero or more jumps and ends on exactly one platform while every other platform has sunk, summed over all starting platforms.
On each of the next lines, print the same count after the -th move.
Constraints
- The platform positions are distinct at the start and after every query.
- All given numbers are integers.