8166: K-King of Range

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:51 通过:22

题目描述

Given n integers a1,a2,⋯,an and queries. For each query, you are given a const k and you should determine how many different pairs (l,r) are there meeting the condition that the range of the subsequence al,al+1,⋯,ar is strictly greater than k.

Note: the range of a sequence equals the difference between the maximum and the minimum of the sequence.

输入描述:

The first line contains two integers n, m (1 <= n <= 1e5, 1 <= m <= 200), denoting the number of given integers and the number of queries respectively.
The second line contains n integers a1, a2, ... , an(1 <= ai <= 1e9), denoting the given integers.
Next m lines each contains one integer k(1 <= k <= 1e9) , denoting the queries.

输出描述:

Print m lines each contains one integer, denoting the answers.

输入格式

5 1
1 2 3 4 5
2

输出格式

3

输入样例 复制

5 1
1 2 3 4 5
2

输出样例 复制

3

数据范围与提示

There are three pairs(1, 4)(1, 5)(2, 5)which meet the condition.