#abc371d. D - 1D Country

D - 1D Country

Score : 350350 points

问题陈述

在数轴上有 NN 个村庄。第 ii 个村庄位于坐标 XiX_i,并且有 PiP_i 个村民。

回答 QQ 个查询。第 ii 个查询的格式如下:

  • 给定整数 LiL_iRiR_i,找出位于坐标 LiL_iRiR_i 之间(包括 LiL_iRiR_i)的村庄中居住的村民总数。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

There are NN villages on a number line. The ii-th village is located at coordinate XiX_i, and has PiP_i villagers.

Answer QQ queries. The ii-th query is in the following format:

  • Given integers LiL_i and RiR_i, find the total number of villagers living in villages located between coordinates LiL_i and RiR_i, inclusive.

Constraints

  • 1N,Q2×1051\leq N,Q\leq 2\times 10^5
  • 109X1<X2<<XN109-10^9\leq X_1 < X_2 < \ldots < X_N \leq 10^9
  • 1Pi1091\leq P_i\leq 10^9
  • 109LiRi109-10^9\leq L_i \leq R_i \leq 10^9
  • All input values are integers.

Input

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

NN

X1X_1 \ldots XNX_N

P1P_1 \ldots PNP_N

QQ

L1L_1 R1R_1

\vdots

LQL_Q RQR_Q

Output

Print QQ lines.

The ii-th line(1iQ)(1\leq i \leq Q) should contain the answer to the ii-th query.

Sample Input 1

4
1 3 5 7
1 2 3 4
4
1 1
2 6
0 10
2 2

Sample Output 1

1
5
10
0

Consider the first query. The villages between coordinates 11 and 11 are the village at coordinate 11, with 11 villager. Hence, the answer is 11.

Consider the second query. The villages between coordinates 22 and 66 are the villages at coordinates 33 and 55, with 22 and 33 villagers, respectively. Hence, the answer is 2+3=52+3=5.

Sample Input 2

7
-10 -5 -3 -1 0 1 4
2 5 6 5 2 1 7
8
-7 7
-1 5
-10 -4
-8 10
-5 0
-10 5
-8 7
-8 -3

Sample Output 2

26
15
7
26
18
28
26
11
}