AT_abc477_e.Wheel Distance

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an edge-weighted undirected graph with N+1N+1 vertices numbered 11 to N+1N+1.
For each integer ii satisfying 1≤i≤N1 \leq i \leq N, there is an edge of weight AiA_i connecting vertex ii and vertex (i mod N)+1(i \bmod N) + 1.
Also, for each integer ii satisfying 1≤i≤N1 \leq i \leq N, there is an edge of weight BiB_i connecting vertex ii and vertex N+1N+1. There are no other edges.

Process QQ queries. In each query, you are given SS and TT; find the length of the shortest path from vertex SS to vertex TT.

给你一个带边权的无向图,该图共有 N+1N+1 个顶点,编号为 11 到 N+1N+1。
对每个满足 1≤i≤N1 \leq i \leq N 的整数 ii,存在一条连接顶点 ii 与顶点 (i mod N)+1(i \bmod N) + 1、权重为 AiA_i 的边。
此外,对每个满足 1≤i≤N1 \leq i \leq N 的整数 ii,存在一条连接顶点 ii 与顶点 N+1N+1、权重为 BiB_i 的边。图中不存在其他边。

你需要处理 QQ 个查询。在每个查询中,给定起点 SS 和终点 TT,请计算从顶点 SS 到顶点 TT 的最短路径长度。

输入格式

The input is given from Standard Input in the following format:

NN QQ
A1A_1 A2A_2 …\dots ANA_N
B1B_1 B2B_2 …\dots BNB_N
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

Each query queryq\mathrm{query}_q is given in the following format:

SS TT

输入从标准输入中按以下格式给出:

NN QQ
A1A_1 A2A_2 …\dots ANA_N
B1B_1 B2B_2 …\dots BNB_N
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

每个查询 queryq\mathrm{query}_q 按以下格式给出:

SS TT

输出格式

Output QQ lines. The qq-th line should contain the answer to the qq-th query.

输出 QQ 行。第 qq 行应包含第 qq 个查询的答案。

输入输出样例

  • 输入#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 22 to vertex 55 is 2→1→52\to1\to5, and its length is A1+A5=1+5=6A_1+A_5=1+5=6.

Constraints

  • 3≤N≤2×1053 \leq N \leq 2 \times 10^5
  • 1≤Q≤2×1051 \leq Q \leq 2 \times 10^5
  • 1≤Ai,Bi≤1091 \leq A_i, B_i \leq 10^9
  • 1≤S<T≤N+11 \leq S \lt T \leq N+1
  • All input values are integers.

样例 1 解释:
对于第一个查询,从顶点 22 到顶点 55 的一条最短路径为 2→1→52\to1\to5,其长度为 A1+A5=1+5=6A_1+A_5=1+5=6。

约束条件

  • 3≤N≤2×1053 \leq N \leq 2 \times 10^5
  • 1≤Q≤2×1051 \leq Q \leq 2 \times 10^5
  • 1≤Ai,Bi≤1091 \leq A_i, B_i \leq 10^9
  • 1≤S<T≤N+11 \leq S \lt T \leq N+1
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页