AT_abc477_e.Wheel Distance
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an edge-weighted undirected graph with N+1 vertices numbered 1 to N+1.
For each integer i satisfying 1≤i≤N, there is an edge of weight Ai connecting vertex i and vertex (imodN)+1.
Also, for each integer i satisfying 1≤i≤N, there is an edge of weight Bi connecting vertex i and vertex N+1. There are no other edges.
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.
给你一个带边权的无向图,该图共有 N+1 个顶点,编号为 1 到 N+1。
对每个满足 1≤i≤N 的整数 i,存在一条连接顶点 i 与顶点 (imodN)+1、权重为 Ai 的边。
此外,对每个满足 1≤i≤N 的整数 i,存在一条连接顶点 i 与顶点 N+1、权重为 Bi 的边。图中不存在其他边。
你需要处理 Q 个查询。在每个查询中,给定起点 S 和终点 T,请计算从顶点 S 到顶点 T 的最短路径长度。
输入格式
The input is given from Standard Input in the following format:
N Q
A1 A2 … AN
B1 B2 … BN
query1
query2
⋮
queryQ
Each query queryq is given in the following format:
S T
输入从标准输入中按以下格式给出:
N Q
A1 A2 … AN
B1 B2 … BN
query1
query2
⋮
queryQ
每个查询 queryq 按以下格式给出:
S T
输出格式
Output Q lines. The q-th line should contain the answer to the q-th query.
输出 Q 行。第 q 行应包含第 q 个查询的答案。
输入输出样例
输入#1
5 3 1 3 4 2 5 5 2 4 3 7 2 5 5 6 1 4
输出#1
6 5 6
输入#2
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
输出#2
73248844 265090269 226395315 244911927 150839817 7398452 90418863 68674005 226395315 198612707 68865651 265090269
说明/提示
Sample 1 Explanation:
For the first query, one shortest path from vertex 2 to vertex 5 is 2→1→5, and its length is A1+A5=1+5=6.
Constraints
- 3≤N≤2×105
- 1≤Q≤2×105
- 1≤Ai,Bi≤109
- 1≤S<T≤N+1
- All input values are integers.
样例 1 解释:
对于第一个查询,从顶点 2 到顶点 5 的一条最短路径为 2→1→5,其长度为 A1+A5=1+5=6。
约束条件
- 3≤N≤2×105
- 1≤Q≤2×105
- 1≤Ai,Bi≤109
- 1≤S<T≤N+1
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?