33OJ
登录 注册

#ABC479D. 往返距离 / Back and Forth Distance

往返距离 / Back and Forth Distance

Problem Statement

There are NN squares arranged in a row, numbered 1,2,…,N1, 2, \ldots, N from left to right.

When you are on square ii, you can make one of the following moves.

  • Choose an integer jj such that 1≤j<i1 \leq j < i, and move to square jj. The cost of this move is LiL_i.
  • Choose an integer jj such that i<j≤Ni < j \leq N, and move to square jj. The cost of this move is RiR_i.

You are given QQ queries. Answer each of them. Each query is in the following format.

  • Integers ss and tt are given. Find the minimum total cost required to reach square tt from square ss by repeatedly making moves.

Constraints

  • 2≤N≤3×1052 \leq N \leq 3 \times 10^5
  • 1≤Q≤3×1051 \leq Q \leq 3 \times 10^5
  • 1≤Li≤1091 \leq L_i \leq 10^9 (2≤i≤N)(2 \leq i \leq N)
  • 1≤Ri≤1091 \leq R_i \leq 10^9 (1≤i≤N−1)(1 \leq i \leq N - 1)
  • 1≤s,t≤N1 \leq s, t \leq N for each query.
  • s≠ts \neq t for each query.
  • All input values are integers.

Input

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

  • NN QQ
  • L2L_2 L3L_3 …\ldots LNL_N
  • R1R_1 R2R_2 …\ldots RN−1R_{N - 1}
  • query1\text{query}_1
  • query2\text{query}_2
  • ⋮\vdots
  • queryQ\text{query}_Q

Here, queryi\text{query}_i is the ii-th query, given in the following format:

  • ss tt

Output

Output QQ lines.

The ii-th line should contain the answer to the ii-th query.

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

We explain the first and second queries.

For the first query, if you move directly from square 11 to square 22, the total cost is R1=3R_1 = 3, which is the minimum possible total cost.

For the second query, if you move from square 22 to square 44 and then from square 44 to square 11, the total cost is R2+L4=3R_2 + L_4 = 3, which is the minimum possible total cost.