Problem Statement There are N N villages on a number line. The i i-th village is located…
- User
Problem Statement There are N N villages on a number line. The i i-th village is located at coordinate X i X i , and has P i P i villagers.
Answer Q Q queries. The i i-th query is in the following format:
Given integers L i L i and R i R i , find the total number of villagers living in villages located between coordinates L i L i and R i R i , inclusive. Constraints 1 ≤ N , Q ≤ 2 × 1 0 5 1≤N,Q≤2×10 5
− 1 0 9 ≤ X 1 < X 2 < … < X N ≤ 1 0 9 −10 9 ≤X 1 <X 2 <…<X N ≤10 9
1 ≤ P i ≤ 1 0 9 1≤P i ≤10 9
− 1 0 9 ≤ L i ≤ R i ≤ 1 0 9 −10 9 ≤L i ≤R i ≤10 9
All input values are integers. Input The input is given from Standard Input in the following format:
N N X 1 X 1
… … X N X N
P 1 P 1
… … P N P N
Q Q L 1 L 1
R 1 R 1
⋮ ⋮ L Q L Q
R Q R Q
Output Print Q Q lines.
The i i-th line ( 1 ≤ i ≤ Q ) (1≤i≤Q) should contain the answer to the i i-th query.
Sample 1 Inputcopy Outputcopy 4 1 3 5 7 1 2 3 4 4 1 1 2 6 0 10 2 2 1 5 10 0 Consider the first query. The villages between coordinates 1 1 and 1 1 are the village at coordinate 1 1, with 1 1 villager. Hence, the answer is 1 1.
Consider the second query. The villages between coordinates 2 2 and 6 6 are the villages at coordinates 3 3 and 5 5, with 2 2 and 3 3 villagers, respectively. Hence, the answer is 2 + 3
5 2+3=5.
Sample 2 Inputcopy Outputcopy 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 26 15 7 26 18 28 26 11 segment tree ile yazsana
- Assistant