题库练习 Lipshitz Sequence
← 上一题 下一题 →

A10121 | Lipshitz Sequence

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

A function ![](/uploads/luogu/CF601B/430ebcefe96c88310ccd261882b0ff945145df52_d36c10372638.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 ![](/uploads/acgo/image/ad552118a3e23da8_c57c83df8549.jpeg). We'll deal with a more... discrete version of this term.

For an array ![](/uploads/luogu/CF601B/ccfdce10ff74cd472d9792ed111da871e7a50f00_16f3e7caaf0e.png), we define it's Lipschitz constant ![](/uploads/acgo/image/034612bf3c7ca9e4_0fdc4a063980.jpeg) as follows:

- if $n<2$ , ![](/uploads/acgo/image/73b8bccbffca81bb_ae71f12c52f4.jpeg)
- if $n>=2$ , ![](/uploads/acgo/image/f437eb4897df8c76_76627e048102.jpeg) over all $1<=i<j<=n$

In other words, ![](/uploads/acgo/image/17eaae50c3f74396_af2c558a26b3.jpeg) 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 ![](/uploads/luogu/CF601B/3c996d04a1a028eb850ea279befed0060d54e243_d54b3cce22d9.png) of size $n$ and $q$ queries of the form $[l,r]$ . For each query, consider the subarray ![](/uploads/luogu/CF601B/fab57d281524c7eb59473c192b040dba9062a2ef_ce949114c7e3.png); determine the sum of Lipschitz constants of all subarrays of ![](/uploads/acgo/image/b72a75bc9c795f1a_bf88603f7be5.jpeg).

输入格式

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 ![](/uploads/acgo/image/e4e0430bca932656_f0ae4485673d.jpeg) and the number of queries respectively.

The second line contains $n$ space-separated integers ![](/uploads/luogu/CF601B/a894c656178c8b0dc4902212cccb3f110230b59c_3dd5cfa804b0.png) (![](/uploads/acgo/image/aa42afa6b08a2d23_9f1b813ca711.jpeg)).

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 ![](/uploads/acgo/image/1a49effa4f45ec7f_c749f0fc737c.jpeg).

输入输出样例

输入 #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
C++ 编辑器
输入
输出