AT_abc479_d.Back and Forth Distance
普及-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are N squares arranged in a row, numbered 1,2,…,N from left to right.
When you are on square i, you can make one of the following moves.
-
Choose an integer j such that 1≤j<i, and move to square j. The cost of this move is Li.
-
Choose an integer j such that i<j≤N, and move to square j. The cost of this move is Ri.
You are given Q queries. Answer each of them. Each query is in the following format.
- Integers s and t are given. Find the minimum total cost required to reach square t from square s by repeatedly making moves.
有 N 个正方形从左到右依次排列,编号为 1,2,…,N。
当你位于第 i 个正方形时,你可以执行以下两种移动之一:
-
选择一个整数 j,满足 1≤j<i,然后移动到第 j 个正方形。该移动的代价为 Li。
-
选择一个整数 j,满足 i<j≤N,然后移动到第 j 个正方形。该移动的代价为 Ri。
你将收到 Q 个查询,需对每个查询作答。每个查询的格式如下:
- 给定整数 s 和 t,求从第 s 个正方形出发,通过若干次上述移动到达第 t 个正方形所需的最小总代价。
输入格式
The input is given from Standard Input in the following format:
N Q
L2 L3 … LN
R1 R2 … RN−1
query1
query2
⋮
queryQ
Here, queryi is the i-th query, given in the following format:
s t
输入从标准输入中按以下格式给出:
N Q
L2 L3 … LN
R1 R2 … RN−1
query1
query2
⋮
queryQ
其中,queryi 表示第 i 个查询,其格式如下:
s t
输出格式
Output Q lines.
The i-th line should contain the answer to the i-th query.
输出 Q 行。
第 i 行应包含第 i 个查询的答案。
输入输出样例
输入#1
5 7 5 6 2 9 3 1 3 8 1 2 2 1 2 4 3 2 3 5 4 3 5 2
输出#1
3 3 1 5 3 2 9
说明/提示
Sample 1 Explanation:
We explain the first and second queries.
For the first query, if you move directly from square 1 to square 2, the total cost is R1=3, which is the minimum possible total cost.
For the second query, if you move from square 2 to square 4 and then from square 4 to square 1, the total cost is R2+L4=3, which is the minimum possible total cost.
Constraints
- 2≤N≤3×105
- 1≤Q≤3×105
- 1≤Li≤109 (2≤i≤N)
- 1≤Ri≤109 (1≤i≤N−1)
- 1≤s,t≤N for each query.
- s=t for each query.
- All input values are integers.
样例 1 解释:
我们解释第一个和第二个查询。
对于第一个查询,若直接从方格 1 移动到方格 2,总代价为 R1=3,这是可能的最小总代价。
对于第二个查询,若从方格 2 移动到方格 4,再从方格 4 移动到方格 1,总代价为 R2+L4=3,这是可能的最小总代价。
约束条件
- 2≤N≤3×105
- 1≤Q≤3×105
- 1≤Li≤109 (2≤i≤N)
- 1≤Ri≤109 (1≤i≤N−1)
- 每个查询中,1≤s,t≤N。
- 每个查询中,s=t。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?