#FT0000173. Tổng giao các hình chữ nhật có trọng số (Static Rectangle Add Rectangle Sum)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tổng giao các hình chữ nhật có trọng số (Static Rectangle Add Rectangle Sum)
Static Rectangle Add Rectangle Sum
Source: Library Checker
Version: Phước Hưng OJ Extended
Problem Statement
You are given weighted half-open rectangles . For each of half-open query rectangles , compute the weighted sum of intersection areas, summing the intersection area against every initial rectangle multiplied by its weight:
$$\sum_{i=1}^{N}w_i\,\max(0,\min(r,r_i)-\max(l,l_i))\,\max(0,\min(u,u_i)-\max(d,d_i)).$$Overlaps between the initial rectangles contribute separately. Print each result modulo . The initial rectangles are static; there are no updates.
Input
The first line contains , followed by lines l d r u w describing weighted rectangles and lines l d r u describing query rectangles.
Output
For each query rectangle, output its weighted intersection area sum modulo .
Subtask
- Subtask 1 (20 points): ; ; every integer rectangle has , ; ; output is modulo .
- Subtask 2 (30 points): ; ; every integer rectangle has , ; ; output is modulo .
- Subtask 3 (50 points): ; ; every integer rectangle has , ; ; output is modulo .
Examples
Example 1
Input
2 4
0 0 3 3 2
2 1 4 4 3
0 0 4 4
2 1 3 3
0 0 2 2
3 3 4 4
Output
36
10
8
3
Explanation
The first rectangle has area 9 and weight 2, contributing 18 to the full-region query. The second has area 6 and weight 3, contributing another 18, for 36. The second query intersects each rectangle in a region, yielding . The third overlaps only the first rectangle in a region, yielding 8. The last overlaps only the second in one unit square, yielding 3.
Example 2
Input
1 3
0 0 1000000000 1000000000 998244352
0 0 1 1
0 0 2 2
100 100 101 101
Output
998244352
998244349
998244352
Explanation
The weight is congruent to modulo . The first intersection has area 1 and yields . The second has area 4 and yields . The third has area 1 again and yields .