請你實現一個類 SubrectangleQueries ,它的構造函數的參數是一個 rows x cols 的矩形(這里用整數矩陣表示),并支持以下兩種操作:
- updateSubrectangle(int row1, int col1, int row2, int col2, int newValue)
用 newValue 更新以 (row1,col1) 為左上角且以 (row2,col2) 為右下角的子矩形。
2. getValue(int row, int col)
返回矩形中坐標 (row,col) 的當前值。
代碼
class SubrectangleQueries {int[][] rect;public SubrectangleQueries(int[][] rectangle) {rect=rectangle;}public void updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) {for(int i=row1;i<=row2;i++)for(int j=col1;j<=col2;j++)rect[i][j]=newValue;}public int getValue(int row, int col) {return rect[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);*/