#FT0000166. Tổng trọng số các điểm trong hình chữ nhật (Rectangle Sum)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tổng trọng số các điểm trong hình chữ nhật (Rectangle Sum)
Rectangle Sum
Source: Library Checker
Version: Phước Hưng OJ Extended.
Problem Statement
There are weighted points at integer coordinates , each with weight . Several points may occupy the same coordinate; they are separate instances and all their weights contribute. Each of queries specifies the half-open rectangle . Output the sum of weights of precisely those points satisfying and . The left and lower boundaries are included, while the right and upper boundaries are excluded. Queries do not modify the points.
Input
The first line contains . Each of the next lines gives x y w. Each of the next lines gives one half-open rectangle l d r u.
Output
For each query, print the sum of the included weights as a 64-bit integer.
Subtask
- Subtask 1 (20 points): ; ; ; each query has , .
- Subtask 2 (30 points): ; ; ; each query has , .
- Subtask 3 (50 points): ; ; ; each query has , .
Examples
Example 1
Input
5 5
0 0 1
3 0 10
1 4 100
2 2 1000
3 2 10000
0 0 4 5
0 0 4 4
3 0 4 3
2 0 4 3
1 2 2 4
Output
11111
11011
10010
11010
0
Explanation
The five points have weights . Query 1 includes all five, totaling . Query 2 excludes because the top edge is open, giving . Query 3 includes the two points with , totaling . Query 4 includes weights . Query 5 contains no point, giving 0.
Example 2
Input
4 4
1 1 3
1 1 4
3 0 10
4 4 5
1 1 2 2
1 1 4 5
0 0 5 5
3 0 4 1
Output
7
7
22
10
Explanation
The two distinct points at contribute . The second rectangle again contains only these two points because lies below its lower bound. The third contains all four points with total . The final rectangle contains just , yielding .