Codeforces Round 789 (Div. 1)
E
Tokitsukaze and Beautiful Subsegments
Codeforces
2900
原题
← DF →
翻译中…

Tokitsukaze has a permutation $p$ of length $n$.

翻译中…

Let's call a segment $[l,r]$ beautiful if there exist $i$ and $j$ satisfying $p_i \cdot p_j = \max\{p_l, p_{l+1}, \ldots, p_r \}$, where $l \leq i \lt j \leq r$.

翻译中…

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

翻译中…

Input

翻译中…

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

翻译中…

The second line contains $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq n$) — the permutation $p$.

翻译中…

Each of the next $q$ lines contains two integers $l_i$ and $r_i$ ($1 \leq l_i \leq r_i \leq n$) — the segment $[l_i,r_i]$ of this query.

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

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

翻译中…

样例

Input #1
8 3
1 3 5 2 4 7 6 8
1 3
1 1
1 8
Output #1
2
0
10
InputCopy OutputCopy
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
Output #2
17
25
1
5
2
0
4
1
0
0
InputCopy OutputCopy
题目信息
题号
1677E
时间限制
4 s
内存限制
1024 MB
标签
数据结构

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。