往返距离AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)There are $N$ squares arranged in a row, numbered $1, 2, \ldots, N$ from left to right.
有 $N$ 个格子排成一行,从左到右编号为 $1, 2, \ldots, N$。AI (CI翻译)
When you are on square $i$, you can make one of the following moves.
当你位于格子 $i$ 时,可以进行以下操作之一。AI (CI翻译)
- Choose an integer
$j$such that$1 \leq j < i$, and move to square$j$. The cost of this move is$L_i$. - Choose an integer
$j$such that$i < j \leq N$, and move to square$j$. The cost of this move is$R_i$.
- 选择一个整数
$j$,满足$1 \leq j < i$,并移动到格子$j$。这次移动的代价为$L_i$。 - 选择一个整数
$j$,满足$i < j \leq N$,并移动到格子$j$。这次移动的代价为$R_i$。
You are given $Q$ queries. Answer each of them. Each query is in the following format.
给定 $Q$ 个询问,请逐一回答。每个询问的格式如下。AI (CI翻译)
- Integers
$s$and$t$are given. Find the minimum total cost required to reach square$t$from square$s$by repeatedly making moves.
- 给定整数
$s$和$t$。求通过重复进行上述移动,从格子$s$到达格子$t$所需的最小总代价。
Constraints
约束条件
AI (CI翻译)$2 \leq N \leq 3 \times 10^5$$1 \leq Q \leq 3 \times 10^5$$1 \leq L_i \leq 10^9$$(2 \leq i \leq N)$$1 \leq R_i \leq 10^9$$(1 \leq i \leq N - 1)$$1 \leq s, t \leq N$for each query.$s \neq t$for each query.- All input values are integers.
$2 \leq N \leq 3 \times 10^5$$1 \leq Q \leq 3 \times 10^5$$1 \leq L_i \leq 10^9$$(2 \leq i \leq N)$$1 \leq R_i \leq 10^9$$(1 \leq i \leq N - 1)$- 对于每个询问,
$1 \leq s, t \leq N$。 - 对于每个询问,
$s \neq t$。 - 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
N Q
L_2 L_3 \ldots L_N
R_1 R_2 \ldots R_{N - 1}
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
N Q
L_2 L_3 \ldots L_N
R_1 R_2 \ldots R_{N - 1}
\text{query}_1
\text{query}_2
\vdots
\text{query}_QAI (CI翻译)
Here, $\text{query}_i$ is the $i$-th query, given in the following format:
其中,$\text{query}_i$ 表示第 $i$ 个询问,格式如下:AI (CI翻译)
s t
s tAI (CI翻译)
Output
输出格式
AI (CI翻译)Output $Q$ lines.
输出 $Q$ 行。AI (CI翻译)
The $i$-th line should contain the answer to the $i$-th query.
第 $i$ 行应包含第 $i$ 个询问的答案。AI (CI翻译)
样例
5 7
5 6 2 9
3 1 3 8
1 2
2 1
2 4
3 2
3 5
4 3
5 2
3
3
1
5
3
2
9
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。