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

#FT0000019. Các thao tác trên ma trận (Operations on a Matrix)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Các thao tác trên ma trận (Operations on a Matrix)

Operations on a Matrix

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Consider an n×mn\times m matrix whose rows and columns are indexed from 11. Every cell is initially zero. Process qq commands that modify columns, overwrite a row, or read a cell.

Operation 1 l r x adds xx to every cell in columns l,l+1,…,rl,l+1,\ldots,r of all rows. Operation 2 i x assigns the entire row ii to xx: each cell in that row becomes exactly xx, regardless of additions made earlier. Operation 3 i j asks for the current value in row ii, column jj.

Operation order is essential. A row assignment overwrites the effects of all previous column additions on that row, but later column additions still affect it. No other row is affected by assigning row ii.

Input

  • Line 1: n m q gives number of rows, columns, and commands.
  • Next qq lines: each line contains one of the following commands, in execution order:
    • 1 l r x: add xx to columns ll through rr of all rows.
    • 2 i x: set every cell in row ii to xx.
    • 3 i j: query the cell at row ii, column jj.

Output

For each 3 i j command, print the current value of the cell at row ii, column jj, on a separate line. Neither update command produces output.

Subtasks

Subtask 1 (20 points):

  • 1≤n≤241\le n\le 24.
  • 1≤m≤241\le m\le 24.
  • 1≤q≤301\le q\le 30.
  • operation 1: 1≤l≤r≤m1\le l\le r\le m, 1≤x≤1091\le x\le 10^9.
  • operation 2: 1≤i≤n1\le i\le n, 1≤x≤1091\le x\le 10^9.
  • operation 3: 1≤i≤n1\le i\le n, 1≤j≤m1\le j\le m.
  • there is at least one operation loại 3.

Subtask 2 (30 points):

  • 1≤n≤12001\le n\le 1200.
  • 1≤m≤12001\le m\le 1200.
  • 1≤q≤16001\le q\le 1600.
  • operation 1: 1≤l≤r≤m1\le l\le r\le m, 1≤x≤1091\le x\le 10^9.
  • operation 2: 1≤i≤n1\le i\le n, 1≤x≤1091\le x\le 10^9.
  • operation 3: 1≤i≤n1\le i\le n, 1≤j≤m1\le j\le m.
  • there is at least one operation loại 3.

Subtask 3 (50 points):

  • 1≤n≤2000001\le n\le 200000.
  • 1≤m≤2000001\le m\le 200000.
  • 1≤q≤2000001\le q\le 200000.
  • operation 1: 1≤l≤r≤m1\le l\le r\le m, 1≤x≤1091\le x\le 10^9.
  • operation 2: 1≤i≤n1\le i\le n, 1≤x≤1091\le x\le 10^9.
  • operation 3: 1≤i≤n1\le i\le n, 1≤j≤m1\le j\le m.
  • there is at least one operation loại 3.

Examples

Input

3 4 6
1 1 2 5
3 2 1
2 2 7
3 2 1
1 2 4 3
3 2 2

Output

5
7
10

Explanation

Here n=3n=3, m=4m=4. Initially all three matrix rows are [0, 0, 0, 0].

  1. 1 1 2 5: add 55 to columns 1 and 2 of every row. Each row becomes [5, 5, 0, 0].

  2. 3 2 1: cell (2,1)(2,1) equals 55, so print 5.

  3. 2 2 7: set every cell of row 2 to 77. That row becomes [7, 7, 7, 7]; rows 1 and 3 remain [5, 5, 0, 0].

  4. 3 2 1: cell (2,1)(2,1) is now 77, not 1212: its previous additions were overwritten by the row assignment. Print 7.

  5. 1 2 4 3: add 33 to columns 2, 3, and 4 of all rows. Row 2 becomes [7, 10, 10, 10], and rows 1 and 3 become [5, 8, 3, 3].

  6. 3 2 2: cell (2,2)(2,2) equals 7+3=107+3=10 because the column addition happened after the row assignment. Print 10.

The three type-3 queries produce 5, 7, and 10 in this order.