CF601B.Lipshitz Sequence

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A function is called Lipschitz continuous if there is a real constant KK such that the inequality f(x)f(y)<=Kxy|f(x)-f(y)|<=K·|x-y| holds for all . We'll deal with a more... discrete version of this term.

For an array , we define it's Lipschitz constant as follows:

  • if n<2 ,
  • if n>=2n>=2 , over all 1<=i<j<=n

In other words, is the smallest non-negative integer such that h[i]h[j]<=Lij|h[i]-h[j]|<=L·|i-j| holds for all 1<=i,j<=n1<=i,j<=n .

You are given an array of size nn and qq queries of the form [l,r][l,r] . For each query, consider the subarray ; determine the sum of Lipschitz constants of all subarrays of .

输入格式

The first line of the input contains two space-separated integers nn and qq ( 2<=n<=1000002<=n<=100000 and 1<=q<=1001<=q<=100 ) — the number of elements in array and the number of queries respectively.

The second line contains nn space-separated integers ().

The following qq lines describe queries. The ii -th of those lines contains two space-separated integers lil_{i} and rir_{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 ii -th query, print one line containing a single integer — the sum of Lipschitz constants of all subarrays of .

输入输出样例

  • 输入#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 with length at least 22 are:

The answer to the query is their sum.

首页