Lipshitz Sequence
题意翻译
**【题目翻译】**
对于一个序列 $v_{1...n}$,当 $1\leq x<y\leq n$ 且 $x,y$ 均为整数时,同样满足$|v_x-v_y|\leq K\times |x-y|$,则称 $K$ 的最小整数值为序列 $v$ 的 Lipschitz 常数。现在给你一个长度为 $n$ 的序列 $v$ 并给出 $q$ 个询问,对于每对询问 $[l,r]$, 你需要求出 $v_{l...r}$ 的所有连续子序列(子段)$v_{x,y}(l\leq x<y\leq r)$ 的 Lipschitz 常数之和。
**【输入格式】**
第一行两个整数 $n$ 和 $q$,分别表示序列的长度以及询问的个数。
第二行 $n$ 个数,表示序列 $v,(0\leq v_i\leq 10^8)$。接下来 $q$ 行,每行两个数 $l$ 和 $r$,表示询问的区间为 $[l,r]$。
**【输出格式】**
对于每个询问,输出一行一个数,即 $v_{l,r}$ 的所有连续子序列(子段)的 Lipschitz 常数之和。
题目描述
A function ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/430ebcefe96c88310ccd261882b0ff945145df52.png) is called Lipschitz continuous if there is a real constant $ K $ such that the inequality $ |f(x)-f(y)|<=K·|x-y| $ holds for all ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/261d3c24b04ab9fe2bfe5b80cef7a0d93e455362.png). We'll deal with a more... discrete version of this term.
For an array ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/ccfdce10ff74cd472d9792ed111da871e7a50f00.png), we define it's Lipschitz constant ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/dea73c73292e257d3ec0493d833cd87ce60d4100.png) as follows:
- if $ n<2 $ , ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/3ff8c17ca1f7b3e483996c6b0a65fe8821444f77.png)
- if $ n>=2 $ , ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/02820989bea357555f19945647d60c22d98153a5.png) over all $ 1<=i<j<=n $
In other words, ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/7f78e6e27f8b58a065808f48924984c382457583.png) is the smallest non-negative integer such that $ |h[i]-h[j]|<=L·|i-j| $ holds for all $ 1<=i,j<=n $ .
You are given an array ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/3c996d04a1a028eb850ea279befed0060d54e243.png) of size $ n $ and $ q $ queries of the form $ [l,r] $ . For each query, consider the subarray ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/fab57d281524c7eb59473c192b040dba9062a2ef.png); determine the sum of Lipschitz constants of all subarrays of ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/933dbfa1108f94092075e7b3a5cee6b27ee2f330.png).
输入输出格式
输入格式
The first line of the input contains two space-separated integers $ n $ and $ q $ ( $ 2<=n<=100000 $ and $ 1<=q<=100 $ ) — the number of elements in array ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/3c996d04a1a028eb850ea279befed0060d54e243.png) and the number of queries respectively.
The second line contains $ n $ space-separated integers ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/a894c656178c8b0dc4902212cccb3f110230b59c.png) (![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/9e8c0fade12c84c7014a7013ed96f5825cfef4b1.png)).
The following $ q $ lines describe queries. The $ i $ -th of those lines contains two space-separated integers $ l_{i} $ and $ r_{i} $ ( $ 1<=l_{i}<r_{i}<=n $ ).
输出格式
Print the answers to all queries in the order in which they are given in the input. For the $ i $ -th query, print one line containing a single integer — the sum of Lipschitz constants of all subarrays of ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/5d9ebef2ff7149a76a7b22b08cb78cb7d7617492.png).
输入输出样例
输入样例 #1
10 4
1 5 2 9 1 3 4 2 1 7
2 4
3 8
7 10
1 9
输出样例 #1
17
82
23
210
输入样例 #2
7 6
5 7 7 4 6 6 2
1 2
2 3
2 6
1 7
4 7
3 5
输出样例 #2
2
0
22
59
16
8
说明
In the first query of the first sample, the Lipschitz constants of subarrays of ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/6f9417fdcb9c3ca8d78dd9307c5187f8fb187e89.png) with length at least $ 2 $ are:
- ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/ad0807635c6133e89feb982a2e00b9c60b15e05e.png)
- ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/b5fd24d5adf442c68d175bf047b1975f7d5e9c25.png)
- ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF601B/bb2421b16fa9a9eeeb4115e7a2a3b1e115becb80.png)
The answer to the query is their sum.