CF1709B.Also Try Minecraft

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

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 x−1x-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 p−qp - 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.

你正在对《泰拉瑞亚》(Terraria)的新秘密更新进行 Beta 测试。该更新将为游戏加入任务系统!

简而言之,世界地图可表示为一个长度为 nn 的数组,其中第 ii 列的高度为 aia_i。

你需要测试 mm 个任务。第 jj 个任务由两个整数 sjs_j 和 tjt_j 表示。在该任务中,你必须从第 sjs_j 列移动到第 tjt_j 列。任务开始时,你出现在第 sjs_j 列。

每次移动,你可以从第 xx 列移动到第 x−1x-1 列或第 x+1x+1 列。本版本中,你装备了“幽灵靴”(Spectre Boots),允许你飞行。但由于这是 Beta 版本,该装备存在 Bug:它仅允许你在向上移动时飞行,且飞行持续时间无限。当你从高度为 pp 的列移动到高度为 qq 的列时,你会受到一定量的坠落伤害。若 p>qp > q,则你受到 p−qp - q 点坠落伤害;否则(即 p≤qp \leq q),你向上飞行,不受到任何伤害。

对于每个给定的任务,请计算你在完成该任务过程中所能承受的最小坠落伤害总量。

输入格式

The first line of the input contains two integers nn and mm (2≤n≤105;1≤m≤1052 \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 (1≤ai≤1091 \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 (1≤sj,tj≤n;sj≠tj1 \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.

输入的第一行包含两个整数 nn 和 mm(2≤n≤1052 \le n \le 10^5;1≤m≤1051 \le m \le 10^5),分别表示世界的列数以及你需要测试的任务数量。

输入的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9),其中 aia_i 表示世界中第 ii 列的高度。

接下来的 mm 行描述各个任务。其中第 jj 行包含两个整数 sjs_j 和 tjt_j(1≤sj,tj≤n1 \le s_j, t_j \le n;sj≠tjs_j \ne t_j),表示在第 jj 个任务中,你需要从第 sjs_j 列移动到第 tjt_j 列。

注意:sjs_j 可能大于 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.

输出 mm 个整数。其中第 jj 个整数应为完成第 jj 次任务过程中所能受到的最小坠落伤害值。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页