CF1709B.Also Try Minecraft

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are beta testing the new secret Terraria update. This update will add quests to the game!

Simply, the world map can be represented as an array of length nn , where the ii -th column of the world has height aia_i .

There are mm quests you have to test. The jj -th of them is represented by two integers sjs_j and tjt_j . In this quest, you have to go from the column sjs_j to the column tjt_j . At the start of the quest, you are appearing at the column sjs_j .

In one move, you can go from the column xx to the column x1x-1 or to the column x+1x+1 . In this version, you have Spectre Boots, which allow you to fly. Since it is a beta version, they are bugged, so they only allow you to fly when you are going up and have infinite fly duration. When you are moving from the column with the height pp to the column with the height qq , then you get some amount of fall damage. If the height pp is greater than the height qq , you get pqp - q fall damage, otherwise you fly up and get 00 damage.

For each of the given quests, determine the minimum amount of fall damage you can get during this quest.

输入格式

The first line of the input contains two integers nn and mm ( 2n105;1m1052 \le n \le 10^5; 1 \le m \le 10^5 ) — the number of columns in the world and the number of quests you have to test, respectively.

The second line of the input contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai1091 \le a_i \le 10^9 ), where aia_i is the height of the ii -th column of the world.

The next mm lines describe quests. The jj -th of them contains two integers sjs_j and tjt_j ( 1sj,tjn;sjtj1 \le s_j, t_j \le n; s_j \ne t_j ), which means you have to move from the column sjs_j to the column tjt_j during the jj -th quest.

Note that sjs_j can be greater than tjt_j .

输出格式

Print mm integers. The jj -th of them should be the minimum amount of fall damage you can get during the jj -th quest completion.

输入输出样例

  • 输入#1

    7 6
    10 8 9 6 8 12 7
    1 2
    1 7
    4 6
    7 1
    3 5
    4 2

    输出#1

    2
    10
    0
    7
    3
    1
首页