#FT0000019. Các thao tác trên ma trận (Operations on a Matrix)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 matrix whose rows and columns are indexed from . Every cell is initially zero. Process commands that modify columns, overwrite a row, or read a cell.
Operation 1 l r x adds to every cell in columns of all rows. Operation 2 i x assigns the entire row to : each cell in that row becomes exactly , regardless of additions made earlier. Operation 3 i j asks for the current value in row , column .
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 .
Input
- Line 1:
n m qgives number of rows, columns, and commands. - Next lines: each line contains one of the following commands, in execution order:
1 l r x: add to columns through of all rows.2 i x: set every cell in row to .3 i j: query the cell at row , column .
Output
For each 3 i j command, print the current value of the cell at row , column , on a separate line. Neither update command produces output.
Subtasks
Subtask 1 (20 points):
- .
- .
- .
- operation
1: , . - operation
2: , . - operation
3: , . - there is at least one operation loại
3.
Subtask 2 (30 points):
- .
- .
- .
- operation
1: , . - operation
2: , . - operation
3: , . - there is at least one operation loại
3.
Subtask 3 (50 points):
- .
- .
- .
- operation
1: , . - operation
2: , . - operation
3: , . - 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 , . Initially all three matrix rows are [0, 0, 0, 0].
-
1 1 2 5: add to columns 1 and 2 of every row. Each row becomes[5, 5, 0, 0]. -
3 2 1: cell equals , so print5. -
2 2 7: set every cell of row 2 to . That row becomes[7, 7, 7, 7]; rows 1 and 3 remain[5, 5, 0, 0]. -
3 2 1: cell is now , not : its previous additions were overwritten by the row assignment. Print7. -
1 2 4 3: add 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]. -
3 2 2: cell equals because the column addition happened after the row assignment. Print10.
The three type-3 queries produce 5, 7, and 10 in this order.