CF1677E.Tokitsukaze and Beautiful Subsegments
省选/NOI-
通过率:0%
时间限制:4.00s
内存限制:1024MB
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=maxpl,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).
Tokitsukaze 有一个长度为 n 的排列 p。
我们称一个区间 [l,r] 是“优美的”,如果存在下标 i 和 j 满足 pi⋅pj=max{pl,pl+1,…,pr},其中 l≤i<j≤r。
现在 Tokitsukaze 有 q 个询问;在第 i 个询问中,她想知道区间 [li,ri] 中有多少个优美的子区间 [x,y](即满足 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.
第一行包含两个整数 n 和 q(1≤n≤2⋅105;1≤q≤106)—— 分别表示排列 p 的长度以及查询次数。
第二行包含 n 个互不相同的整数 p1,p2,…,pn(1≤pi≤n)—— 即排列 p。
接下来的 q 行,每行包含两个整数 li 和 ri(1≤li≤ri≤n)—— 表示本次查询所对应的区间 [li,ri]。
输出格式
For each query, print one integer — the numbers of beautiful subsegments in the segment [li,ri].
对于每个查询,输出一个整数——区间 [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].
在第一个例子中,对于第一个查询,有 2 个优美的子段——[1,2] 和 [1,3]。
输入解题思路,AI测评打分。不知道怎么写?