A15182 | Also Try Minecraft
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $n$ , where the $i$ -th column of the world has height $a_i$ .
There are $m$ quests you have to test. The $j$ -th of them is represented by two integers $s_j$ and $t_j$ . In this quest, you have to go from the column $s_j$ to the column $t_j$ . At the start of the quest, you are appearing at the column $s_j$ .
In one move, you can go from the column $x$ to the column $x-1$ or to the column $x+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 $p$ to the column with the height $q$ , then you get some amount of fall damage. If the height $p$ is greater than the height $q$ , you get $p - q$ fall damage, otherwise you fly up and get $0$ damage.
For each of the given quests, determine the minimum amount of fall damage you can get during this quest.
Simply, the world map can be represented as an array of length $n$ , where the $i$ -th column of the world has height $a_i$ .
There are $m$ quests you have to test. The $j$ -th of them is represented by two integers $s_j$ and $t_j$ . In this quest, you have to go from the column $s_j$ to the column $t_j$ . At the start of the quest, you are appearing at the column $s_j$ .
In one move, you can go from the column $x$ to the column $x-1$ or to the column $x+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 $p$ to the column with the height $q$ , then you get some amount of fall damage. If the height $p$ is greater than the height $q$ , you get $p - q$ fall damage, otherwise you fly up and get $0$ 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 $n$ and $m$ ( $2 \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 $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \le a_i \le 10^9$ ), where $a_i$ is the height of the $i$ -th column of the world.
The next $m$ lines describe quests. The $j$ -th of them contains two integers $s_j$ and $t_j$ ( $1 \le s_j, t_j \le n; s_j \ne t_j$ ), which means you have to move from the column $s_j$ to the column $t_j$ during the $j$ -th quest.
Note that $s_j$ can be greater than $t_j$ .
The second line of the input contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \le a_i \le 10^9$ ), where $a_i$ is the height of the $i$ -th column of the world.
The next $m$ lines describe quests. The $j$ -th of them contains two integers $s_j$ and $t_j$ ( $1 \le s_j, t_j \le n; s_j \ne t_j$ ), which means you have to move from the column $s_j$ to the column $t_j$ during the $j$ -th quest.
Note that $s_j$ can be greater than $t_j$ .
输出格式
Print $m$ integers. The $j$ -th of them should be the minimum amount of fall damage you can get during the $j$ -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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted