#P15839. [蓝桥杯第一届国际赛] 莲蓬池
[蓝桥杯第一届国际赛] 莲蓬池
Problem Description
Xiao C has a huge pond where many lotus flowers are planted. In summer, many large lotus seedpods grow in the pond.
To understand how the seedpods grow, Xiao C measured the position of each seedpod. Each seedpod corresponds to a coordinate in the 2D Cartesian coordinate system. These coordinates form a sequence, denoted as , where represents the coordinate of the -th seedpod.
Xiao C plans to use magic to collect some of the seedpods. Because his power is limited, he can only collect all seedpods in an interval of the sequence . The energy required for one collection is the sum of the Manhattan distances between every pair of seedpods in that interval (where ).
Now Xiao C gives you multiple collection plans and hopes you can help compute the energy needed to collect the seedpods in each interval. (Each plan is independent.)
Input Format
The first line contains two positive integers and , representing the number of seedpods and the number of queries.
The next lines each contain two integers and , representing the - and -coordinates of the -th seedpod in the sequence.
The next lines each contain two integers and , representing the left and right endpoints of the interval to be collected in this query (the interval includes endpoints).
Output Format
Output lines. The -th line outputs one integer, representing the answer to the -th query.
5 3
1 1
3 3
2 2
1 3
3 1
2 2
2 4
1 5
0
6
24
Hint
Sample Explanation
For the first query: there is only one seedpod.
For the second query:
For the third query:
Constraints
For of the testdata, , .
For of the testdata, , .
For of the testdata, , , .
For another of the testdata, , , .
For all testdata, , , . There may be two seedpods with the same coordinates. The testdata scale has multiple levels.
Translated by ChatGPT 5