Under construction

Still being built. Things may change

Farmer Juan is a barista

Interview

Time limit2sMemory limit512 MB

Summary
Maintain a grid under range-add rectangle updates and point queries, answering each point query using only earlier updates.
Level

Medium6 of 10

Topics
Prefix sum, Matrix, Implementation, Array
Solved
No attempts yet

Problem

Juan is a barista and he also runs a coffee farm. The farm is an N×MN \times M grid, the xx coordinate runs from 11 to NN, and the yy coordinate runs from 11 to MM. Juan performs QQ operations in the order they are given, and each operation is one of these two.

  • Plant seeds: plant one seed of nutrition dd on every cell whose xx coordinate lies in [x1,x2][x_1, x_2] and whose yy coordinate lies in [y1,y2][y_1, y_2].
  • Check nutrition: report the sum of the nutrition of the seeds planted on cell (x,y)(x, y).

A check reflects only the planting operations that come before it. A cell with no seed yet answers 00. Write the program that manages Juan's farm.

Input

The first line contains NN, MM, and QQ. (1≤N,M≤50001 \le N, M \le 5000, 0≤Q≤2×1050 \le Q \le 2 \times 10^5)

Each of the next QQ lines contains one operation.

If the first number on the line is 11, the operation plants seeds and five numbers x1x_1, y1y_1, x2x_2, y2y_2, dd follow. (1≤x1≤x2≤N1 \le x_1 \le x_2 \le N, 1≤y1≤y2≤M1 \le y_1 \le y_2 \le M, −109≤d≤109-10^9 \le d \le 10^9)

If the first number on the line is 22, the operation checks nutrition and two numbers xx and yy follow. (1≤x≤N1 \le x \le N, 1≤y≤M1 \le y \le M)

Output

For every check operation, print its result on its own line, in the order the operations are given.

Examples3

  1. Example 1

    Input
    3 5 2
    1 1 1 3 5 2
    2 3 3
    
    Expected output
    2
    
  2. Example 2

    Input
    4 4 9
    2 2 2
    1 1 1 2 2 5
    2 2 2
    2 3 3
    1 2 2 4 4 -3
    2 2 2
    2 4 4
    1 1 1 4 4 10
    2 1 1
    
    Expected output
    0
    5
    0
    2
    -3
    15
    
  3. Example 3

    Input
    1 1 5
    1 1 1 1 1 1000000000
    1 1 1 1 1 1000000000
    2 1 1
    1 1 1 1 1 -1000000000
    2 1 1
    
    Expected output
    2000000000
    1000000000