#P1677E. Tokitsukaze and Beautiful Subsegments

Tokitsukaze and Beautiful Subsegments

Description

Tokitsukaze has a permutation pp of length nn.

Let's call a segment [l,r][l,r] beautiful if there exist ii and jj satisfying pipj=max{pl,pl+1,,pr}p_i \cdot p_j = \max\{p_l, p_{l+1}, \ldots, p_r \}, where li<jrl \leq i < j \leq r.

Now Tokitsukaze has qq queries, in the ii-th query she wants to know how many beautiful subsegments [x,y][x,y] there are in the segment [li,ri][l_i,r_i] (i. e. lixyril_i \leq x \leq y \leq r_i).

The first line contains two integers nn and qq (1n21051\leq n \leq 2 \cdot 10^5; 1q1061 \leq q \leq 10^6) — the length of permutation pp and the number of queries.

The second line contains nn distinct integers p1,p2,,pnp_1, p_2, \ldots, p_n (1pin1 \leq p_i \leq n) — the permutation pp.

Each of the next qq lines contains two integers lil_i and rir_i (1lirin1 \leq l_i \leq r_i \leq n) — the segment [li,ri][l_i,r_i] of this query.

For each query, print one integer — the numbers of beautiful subsegments in the segment [li,ri][l_i,r_i].

Input

The first line contains two integers nn and qq (1n21051\leq n \leq 2 \cdot 10^5; 1q1061 \leq q \leq 10^6) — the length of permutation pp and the number of queries.

The second line contains nn distinct integers p1,p2,,pnp_1, p_2, \ldots, p_n (1pin1 \leq p_i \leq n) — the permutation pp.

Each of the next qq lines contains two integers lil_i and rir_i (1lirin1 \leq l_i \leq r_i \leq n) — the segment [li,ri][l_i,r_i] of this query.

Output

For each query, print one integer — the numbers of beautiful subsegments in the segment [li,ri][l_i,r_i].

Sample Input 1

8 3
1 3 5 2 4 7 6 8
1 3
1 1
1 8

Sample Output 1

2
0
10

Sample Input 2

10 10
6 1 3 2 5 8 4 10 7 9
1 8
1 10
1 2
1 4
2 4
5 8
4 10
4 7
8 10
5 9

Sample Output 2

17
25
1
5
2
0
4
1
0
0

Note

In the first example, for the first query, there are 22 beautiful subsegments — [1,2][1,2] and [1,3][1,3].