#FT0000170. Cộng hình chữ nhật và truy vấn tổng (Rectangle Add Rectangle Sum)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cộng hình chữ nhật và truy vấn tổng (Rectangle Add Rectangle Sum)
Rectangle Add Rectangle Sum
Source: Luogu
Version: Phước Hưng OJ Extended
Problem Statement
Initially, an matrix contains zeros. Rows and columns are 1-indexed. Process operations in order:
L a b c d delta: add to every cell with and . Previous values remain and are incremented.k a b c d: print the sum of the cells in the inclusive rectangle from to . The command letterkis lowercase.
Updates may overlap, and every query reflects all updates performed earlier.
Input
The first line contains , followed by exactly operations, either L a b c d delta or k a b c d.
Output
For each k command, print the sum of the requested rectangle after all preceding updates.
Subtask
- Subtask 1 (10 points): ; ; ; , ;
Lhas ; each queried sum fits in a signed 32-bit integer. - Subtask 2 (50 points): ; ; ; , ;
Lhas ; each queried sum fits in a signed 32-bit integer. - Subtask 3 (40 points): ; ; ; , ;
Lhas ; each queried sum fits in a signed 32-bit integer.
Examples
Example 1
Input
3 3 6
k 1 1 3 3
L 1 1 2 2 5
k 1 1 3 3
L 2 2 3 3 -2
k 2 2 3 3
k 1 1 2 2
Output
0
20
-3
18
Explanation
Initially all cells are zero. Adding 5 to a square increases the whole-grid sum by . The next operation adds to the bottom-right square; only previously held 5, so its queried sum becomes . The upper-left square originally totaled 20, and only its cell decreases by 2, yielding 18.
Example 2
Input
1 2 6
L 1 1 1 2 3
k 1 1 1 2
L 1 2 1 2 -5
k 1 1 1 2
k 1 2 1 2
k 1 1 1 1
Output
6
1
-2
3
Explanation
After the first update the single row is , totaling 6. The second update changes its second cell to , leaving the first at 3. Thus the row sum is 1, and the final individual-cell queries return and 3.