轮上的距离AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)You are given an edge-weighted undirected graph with $N+1$ vertices numbered $1$ to $N+1$.
For each integer $i$ satisfying $1 \leq i \leq N$, there is an edge of weight $A_i$ connecting vertex $i$ and vertex $(i \bmod N) + 1$.
Also, for each integer $i$ satisfying $1 \leq i \leq N$, there is an edge of weight $B_i$ connecting vertex $i$ and vertex $N+1$. There are no other edges.
给定一个有 $N+1$ 个顶点的带权无向图,顶点编号为 $1$ 到 $N+1$。
对于满足 $1 \leq i \leq N$ 的每个整数 $i$,顶点 $i$ 与顶点 $(i \bmod N) + 1$ 之间有一条权值为 $A_i$ 的边。
此外,对于满足 $1 \leq i \leq N$ 的每个整数 $i$,顶点 $i$ 与顶点 $N+1$ 之间有一条权值为 $B_i$ 的边。除此之外没有其他边。AI (CI翻译)
Process $Q$ queries. In each query, you are given $S$ and $T$; find the length of the shortest path from vertex $S$ to vertex $T$.
处理 $Q$ 个询问。每个询问给定 $S$ 和 $T$,请求出从顶点 $S$ 到顶点 $T$ 的最短路径长度。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$3 \leq N \leq 2 \times 10^5$$1 \leq Q \leq 2 \times 10^5$$1 \leq A_i, B_i \leq 10^9$$1 \leq S \lt T \leq N+1$- All input values are integers.
$3 \leq N \leq 2 \times 10^5$$1 \leq Q \leq 2 \times 10^5$$1 \leq A_i, B_i \leq 10^9$$1 \leq S \lt T \leq N+1$- 输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
N Q
A_1 A_2 \dots A_N
B_1 B_2 \dots B_N
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q
N Q
A_1 A_2 \dots A_N
B_1 B_2 \dots B_N
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_QAI (CI翻译)
Each query $\mathrm{query}_q$ is given in the following format:
每个询问 $\mathrm{query}_q$ 按以下格式给出:AI (CI翻译)
S T
S TAI (CI翻译)
Output
输出格式
AI (CI翻译)Output $Q$ lines. The $q$-th line should contain the answer to the $q$-th query.
输出 $Q$ 行。第 $q$ 行应包含第 $q$ 个询问的答案。AI (CI翻译)
样例
5 3
1 3 4 2 5
5 2 4 3 7
2 5
5 6
1 4
6
5
6
10 12
95786828 55052989 7398452 90695030 73248844 120697567 77915140 68865651 15301338 68674005
690874817 21524935 244587369 529970100 736247510 757265588 993115119 576136368 21553212 219853538
5 6
5 8
2 6
3 7
1 3
3 4
8 11
1 10
2 6
6 8
8 9
5 8
73248844
265090269
226395315
244911927
150839817
7398452
90418863
68674005
226395315
198612707
68865651
265090269
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。