#FT0000167. Thêm điểm và hỏi tổng trọng số hình chữ nhật (Point Add Rectangle Sum)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Thêm điểm và hỏi tổng trọng số hình chữ nhật (Point Add Rectangle Sum)
Point Add Rectangle Sum
Source: Library Checker
Version: Phước Hưng OJ Extended.
Problem Statement
Initially, there are weighted points. Process operations in order:
0 x y w: append a new point at with weight . Even if the coordinate is already occupied, the new point remains a separate instance.1 l d r u: return the sum of weights of all points currently in , so and .
Existing weights never change. A query includes the initial points and only the points inserted by earlier operations.
Input
The first line contains , followed by lines x y w for initial points and then operations 0 x y w or 1 l d r u.
Output
For every type-1 operation, print the weight sum in the half-open rectangle on its own line.
Subtask
- Subtask 1 (20 points): ; ; initial and inserted point coordinates and weights lie in ; queries have , .
- Subtask 2 (30 points): ; ; initial and inserted point coordinates and weights lie in ; queries have , .
- Subtask 3 (50 points): ; ; initial and inserted point coordinates and weights lie in ; queries have , .
Examples
Example 1
Input
4 5
0 0 1
0 2 10
2 0 100
2 2 1000
1 0 0 2 3
1 0 0 3 3
0 2 2 10000
0 1 1 100000
1 1 1 3 3
Output
11
1111
111000
Explanation
The first rectangle includes weights and , giving . The second includes all four initial points, giving . The two insertions add weights at and at . The final rectangle includes these two new points and the original weight , totaling .
Example 2
Input
1 6
1 1 5
1 1 1 2 2
0 1 1 7
1 1 1 2 2
0 2 2 10
1 1 1 3 3
1 2 2 3 3
Output
5
12
22
10
Explanation
Initially, contributes 5. Adding another point at the same coordinate increases its total to rather than replacing 5. Adding weight 10 at makes the larger rectangle sum . The final rectangle includes only , so it returns 10.