#FT0000169. Cộng hình chữ nhật và hỏi giá trị tại điểm (Rectangle Add Point Get)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cộng hình chữ nhật và hỏi giá trị tại điểm (Rectangle Add Point Get)
Rectangle Add Point Get
Source: Library Checker
Version: Phước Hưng OJ Extended.
Problem Statement
Initially, there are weighted rectangles . A rectangle of weight contributes to every integer point within it. Overlapping rectangles contribute additively. Process operations in order:
0 l d r u w: insert an additional weighted rectangle.1 x y: return the sum of weights of all previously inserted rectangles, including the initial ones, that contain .
Each rectangle is half-open, with and . Rectangles are never removed or edited.
Input
The first line contains , followed by lines l d r u w describing the initial rectangles, then operations 0 l d r u w or 1 x y.
Output
For each 1 x y operation, print the accumulated weight at on a separate line.
Subtask
- Subtask 1 (20 points): ; ; every rectangle has , , ; query points have .
- Subtask 2 (30 points): ; ; every rectangle has , , ; query points have .
- Subtask 3 (50 points): ; ; every rectangle has , , ; query points have .
Examples
Example 1
Input
2 5
0 0 3 3 2
2 2 5 5 4
1 1 1
1 2 2
0 1 1 4 4 3
1 2 2
1 4 4
Output
2
6
9
4
Explanation
Point lies only in the first rectangle and receives 2. Point lies in both initial rectangles, giving . Adding with weight 3 makes its value . Point belongs only to the second initial rectangle; it is excluded from the newly added rectangle by the half-open upper and right boundaries, giving 4.
Example 2
Input
1 5
0 0 2 2 7
1 0 0
0 0 0 2 2 5
1 1 1
1 2 1
1 0 2
Output
7
12
0
0
Explanation
Initially, receives 7. Adding an identical rectangle of weight 5 makes the value at equal to . Points and lie on excluded right or upper boundaries, so their values are both zero.