CF1677E.Tokitsukaze and Beautiful Subsegments

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:1024MB

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 pi⋅pj=max⁡pl,pl+1,…,prp_i \cdot p_j = \max{p_l, p_{l+1}, \ldots, p_r }, where l≤i<j≤rl \leq i \lt 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. li≤x≤y≤ril_i \leq x \leq y \leq r_i).

Tokitsukaze 有一个长度为 nn 的排列 pp。

我们称一个区间 [l,r][l,r] 是“优美的”,如果存在下标 ii 和 jj 满足 pi⋅pj=max⁡{pl,pl+1,…,pr}p_i \cdot p_j = \max\{p_l, p_{l+1}, \ldots, p_r\},其中 l≤i<j≤rl \leq i < j \leq r。

现在 Tokitsukaze 有 qq 个询问;在第 ii 个询问中,她想知道区间 [li,ri][l_i,r_i] 中有多少个优美的子区间 [x,y][x,y](即满足 li≤x≤y≤ril_i \leq x \leq y \leq r_i)。

输入格式

The first line contains two integers nn and qq (1≤n≤2⋅1051\leq n \leq 2 \cdot 10^5; 1≤q≤1061 \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 (1≤pi≤n1 \leq p_i \leq n) — the permutation pp.

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

第一行包含两个整数 nn 和 qq(1≤n≤2⋅1051\leq n \leq 2 \cdot 10^5;1≤q≤1061 \leq q \leq 10^6)—— 分别表示排列 pp 的长度以及查询次数。

第二行包含 nn 个互不相同的整数 p1,p2,…,pnp_1, p_2, \ldots, p_n(1≤pi≤n1 \leq p_i \leq n)—— 即排列 pp。

接下来的 qq 行,每行包含两个整数 lil_i 和 rir_i(1≤li≤ri≤n1 \leq l_i \leq r_i \leq n)—— 表示本次查询所对应的区间 [li,ri][l_i,r_i]。

输出格式

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

对于每个查询,输出一个整数——区间 [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].

在第一个例子中,对于第一个查询,有 22 个优美的子段——[1,2][1,2] 和 [1,3][1,3]。

输入解题思路,AI测评打分。不知道怎么写?

首页