CF1677E.Tokitsukaze and Beautiful Subsegments
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Tokitsukaze has a permutation p of length n .
Let's call a segment [l,r] beautiful if there exist i and j satisfying pi⋅pj=max{pl,pl+1,…,pr} , where l≤i<j≤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 [li,ri] (i. e. li≤x≤y≤ri ).
输入格式
The first line contains two integers n and q ( 1≤n≤2⋅105 ; 1≤q≤106 ) — the length of permutation p and the number of queries.
The second line contains n distinct integers p1,p2,…,pn ( 1≤pi≤n ) — the permutation p .
Each of the next q lines contains two integers li and ri ( 1≤li≤ri≤n ) — the segment [li,ri] of this query.
输出格式
For each query, print one integer — the numbers of beautiful subsegments in the segment [li,ri] .
输入输出样例
输入#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 2 beautiful subsegments — [1,2] and [1,3] .