CF1677E.Tokitsukaze and Beautiful Subsegments

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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] .

输入输出样例

  • 输入#1

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

    输出#1

    2
    0
    10
  • 输入#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

    输出#2

    17
    25
    1
    5
    2
    0
    4
    1
    0
    0

说明/提示

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

首页