Problems
Fast Matrix Operations
Fast Matrix Operations
There is a matrix containing at most \textbf{10^6} elements divided into \textbf{r} rows and \textbf{c} columns. Each element has a location (\textbf{x}, \textbf{y}) where \textbf{1} ≤ \textbf{x} ≤ \textbf{r}, \textbf{1} ≤ \textbf{y} ≤ \textbf{c}. Initially, all the elements are zero. You need to handle four kinds of operations:
In the above descriptions, submatrix (\textbf{x1}, \textbf{y1}, \textbf{x2}, \textbf{y2}) means all the elements (\textbf{x}, \textbf{y}) satisfying \textbf{x1} ≤ \textbf{x} ≤ \textbf{x2} and \textbf{y1} ≤ \textbf{x} ≤ \textbf{y2}. It is guaranteed that \textbf{1} ≤ \textbf{x1} ≤ \textbf{x2} ≤ \textbf{r}, \textbf{1} ≤ \textbf{y1} ≤ \textbf{y2} ≤ \textbf{c}. After any operation, the sum of all the elements in the matrix will not exceed \textbf{10^9}.
\InputFile
There are several test cases. The first line of each case contains three positive integers \textbf{r}, \textbf{c}, \textbf{m}, where \textbf{m} (\textbf{1} ≤ \textbf{m} ≤ \textbf{20,000}) is the number of operations. Each of the next \textbf{m} lines contains a query. There will be at most twenty rows in the matrix. The input is terminated by end-of-file (\textbf{EOF}). The size of input file does not exceed \textbf{500} KB.
\OutputFile
For each type-\textbf{3} query, print the summation, min and max.
Input example #1
4 4 8 1 1 2 4 4 5 3 2 1 4 4 1 1 1 3 4 2 3 1 2 4 4 3 1 1 3 4 2 2 1 4 4 2 3 1 2 4 4 1 1 1 4 3 3
Output example #1
45 0 5 78 5 7 69 2 7 39 2 7