PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000161. Ada và những tổ ong (Ada and Behives)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 N×MN\times M area contains bee hives. Cell (i,j)(i,j) initially contains Ai,jA_{i,j} bees. Coordinates are one-based. Process QQ operations in order:

  • 1 i j p: add pp newborn bees to cell (i,j)(i,j).
  • 2 i1 j1 i2 j2: output the number of bees in the inclusive rectangle i1≤i≤i2i1\le i\le i2, j1≤j≤j2j1\le j\le j2.

All earlier additions affect subsequent queries.

Input

The first line contains N,M,QN,M,Q, followed by NN rows of MM initial populations and QQ 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): 1≤N≤61\le N\le 6; 1≤M≤61\le M\le 6; 1≤Q≤501\le Q\le 50; 1≤Ai,j,p≤1041\le A_{i,j},p\le10^4; type-1 coordinates 1≤i≤N1\le i\le N, 1≤j≤M1\le j\le M; type-2 bounds 1≤i1≤i2≤N1\le i1\le i2\le N, 1≤j1≤j2≤M1\le j1\le j2\le M.
  • Subtask 2 (30 points): 1≤N≤1601\le N\le 160; 1≤M≤1601\le M\le 160; 1≤Q≤40001\le Q\le 4000; 1≤Ai,j,p≤1041\le A_{i,j},p\le10^4; type-1 coordinates 1≤i≤N1\le i\le N, 1≤j≤M1\le j\le M; type-2 bounds 1≤i1≤i2≤N1\le i1\le i2\le N, 1≤j1≤j2≤M1\le j1\le j2\le M.
  • Subtask 3 (50 points): 1≤N≤20001\le N\le 2000; 1≤M≤20001\le M\le 2000; 1≤Q≤1000001\le Q\le 100000; 1≤Ai,j,p≤1041\le A_{i,j},p\le10^4; type-1 coordinates 1≤i≤N1\le i\le N, 1≤j≤M1\le j\le M; type-2 bounds 1≤i1≤i2≤N1\le i1\le i2\le N, 1≤j1≤j2≤M1\le j1\le j2\le M.

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 120120, 2020, and 1818. The next operations add 4 bees at (5,4) and 665 at (1,1). The whole-grid total becomes 120+4+665=789120+4+665=789; the top-left region becomes 20+665=68520+665=685; the last queried region becomes 18+4=2218+4=22.

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 2121. Adding 4 at (2,2) changes the second row to (4,9,6), making the queried sum 9+6=159+6=15. Adding 10 at (1,1) makes that cell equal 11. The final column-2 query totals 2+9=112+9=11.