#P1677E. Tokitsukaze and Beautiful Subsegments
Tokitsukaze and Beautiful Subsegments
Description
Tokitsukaze has a permutation of length .
Let's call a segment beautiful if there exist and satisfying , where .
Now Tokitsukaze has queries, in the -th query she wants to know how many beautiful subsegments there are in the segment (i. e. ).
The first line contains two integers and (; ) — the length of permutation and the number of queries.
The second line contains distinct integers () — the permutation .
Each of the next lines contains two integers and () — the segment of this query.
For each query, print one integer — the numbers of beautiful subsegments in the segment .
Input
The first line contains two integers and (; ) — the length of permutation and the number of queries.
The second line contains distinct integers () — the permutation .
Each of the next lines contains two integers and () — the segment of this query.
Output
For each query, print one integer — the numbers of beautiful subsegments in the segment .
Note
In the first example, for the first query, there are beautiful subsegments — and .