#FT0000161. Ada và những tổ ong (Ada and Behives)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Ada và những tổ ong (Ada and Behives)
Ada and Behives
Source: SPOJ
Version: Phuoc Hung OJ – standard input format, original problem semantics preserved.
Problem Statement
An area contains bee hives. Cell initially contains bees. Coordinates are one-based. Process operations in order:
1 i j p: add newborn bees to cell .2 i1 j1 i2 j2: output the number of bees in the inclusive rectangle , .
All earlier additions affect subsequent queries.
Input
The first line contains , followed by rows of initial populations and operation lines of type 1 or 2.
Output
For each type-2 query, output the rectangle population on its own line; the sum may exceed 32-bit signed integer range.
Subtasks
- Subtask 1 (20 points): ; ; ; ; type-
1coordinates , ; type-2bounds , . - Subtask 2 (30 points): ; ; ; ; type-
1coordinates , ; type-2bounds , . - Subtask 3 (50 points): ; ; ; ; type-
1coordinates , ; type-2bounds , .
Examples
Example 1
Input
6 5 8
1 2 3 4 5
1 2 3 4 5
6 6 6 6 6
5 4 3 2 1
5 4 3 2 1
6 6 6 6 6
2 1 1 6 5
2 1 1 2 4
2 4 2 5 4
1 5 4 4
1 1 1 665
2 1 1 6 5
2 1 1 2 4
2 4 2 5 4
Output
120
20
18
789
685
22
Explanation
The initial rectangle sums are , , and . The next operations add 4 bees at (5,4) and 665 at (1,1). The whole-grid total becomes ; the top-left region becomes ; the last queried region becomes .
Example 2
Input
2 3 6
1 2 3
4 5 6
2 1 1 2 3
1 2 2 4
2 2 2 2 3
1 1 1 10
2 1 1 1 1
2 1 2 2 2
Output
21
15
11
11
Explanation
The initial total is . Adding 4 at (2,2) changes the second row to (4,9,6), making the queried sum . Adding 10 at (1,1) makes that cell equal 11. The final column-2 query totals .