This page is still under construction.

Parts of this page are still being built. What you see may change.

Lava Jump 2

Time limit2sMemory limit512 MB

Summary
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 NN platforms, numbered 1 through NN. The position of platform ii is the integer aia_i, and all positions are distinct. That is, ai≠aja_i \ne a_j for all integers ii, jj with 1≤i<j≤N1 \le i < j \le N. 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 xx, every later jump must be at least 2x2x. At first, he can jump any distance.

A jump from platform ii to platform jj has distance ∣ai−aj∣|a_i - a_j|. 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 NN and QQ, the number of platforms and the number of queries.

The second line contains NN integers separated by spaces. The ii-th integer is aia_i, the position of platform ii.

Each of the next QQ lines contains two integers bib_i and cic_i, meaning platform bib_i moves to position cic_i.

Output

On the first line, print the number of ways modulo 109+710^9 + 7 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 QQ lines, print the same count after the ii-th move.

Constraints

  • 1≤N≤40,0001 \le N \le 40{,}000
  • 0≤Q≤40,0000 \le Q \le 40{,}000
  • −1018≤ai,ci≤1018-10^{18} \le a_i, c_i \le 10^{18}
  • 1≤bi≤N1 \le b_i \le N
  • The platform positions are distinct at the start and after every query.
  • All given numbers are integers.

Examples1

  1. Example 1

    Input
    5 1
    10 1 6 7 8
    1 13
    
    Expected output
    1
    2