-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1476-SubrectangleQueries.cs
46 lines (39 loc) · 1.5 KB
/
1476-SubrectangleQueries.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//-----------------------------------------------------------------------------
// Runtime: 180ms
// Memory Usage: 40.4 MB
// Link: https://leetcode.com/submissions/detail/360342817/
//-----------------------------------------------------------------------------
using System.Collections.Generic;
namespace LeetCode
{
public class _1476_SubrectangleQueries
{
private int[][] rectangle;
private IList<(int row1, int col1, int row2, int col2, int value)> updates;
public _1476_SubrectangleQueries(int[][] rectangle)
{
this.rectangle = rectangle;
this.updates = new List<(int row1, int col1, int row2, int col2, int newValue)>();
}
public void UpdateSubrectangle(int row1, int col1, int row2, int col2, int newValue)
{
updates.Add((row1, col1, row2, col2, newValue));
}
public int GetValue(int row, int col)
{
for (int i = updates.Count - 1; i >= 0; i--)
{
var update = updates[i];
if (update.row1 <= row && update.col1 <= col && row <= update.row2 && col <= update.col2)
return update.value;
}
return rectangle[row][col];
}
}
/**
* Your SubrectangleQueries object will be instantiated and called as such:
* SubrectangleQueries obj = new SubrectangleQueries(rectangle);
* obj.UpdateSubrectangle(row1,col1,row2,col2,newValue);
* int param_2 = obj.GetValue(row,col);
*/
}