---
# System prepended metadata

title: 1476. Subrectangle Queries

---

# 1476. Subrectangle Queries

## 題目概要
- 一道題目很長很唬人的題目...
- 要你實現一個類別 `SubrectangleQueries`，它的建構子參數是 rows * cols 的矩陣，並有以下兩個方法：
    - `updateSubrectangle(int row1, int col1, int row2, int col2, int newValue)`，將 從 arr[row1][col1] ~ arr[row2][col2] 的值都改為 newValue。
    - `getValue(int row, int col)` 返回 arr[row][col] 的值。


## 解題技巧
- 堪稱是沒有...

## 程式碼

```javascript=
/**
 * @param {number[][]} rectangle
 */
let arr = [];
var SubrectangleQueries = function(rectangle) {
    arr = rectangle;
};

/** 
 * @param {number} row1 
 * @param {number} col1 
 * @param {number} row2 
 * @param {number} col2 
 * @param {number} newValue
 * @return {void}
 */
SubrectangleQueries.prototype.updateSubrectangle = function(row1, col1, row2, col2, newValue) {
    for (let i = row1; i <= row2; i++) {
       for (let j = col1; j <= col2; j++) {
            arr[i][j] = newValue;
        } 
    }
};

/** 
 * @param {number} row 
 * @param {number} col
 * @return {number}
 */
SubrectangleQueries.prototype.getValue = function(row, col) {
    return arr[row][col];
};

/** 
 * Your SubrectangleQueries object will be instantiated and called as such:
 * var obj = new SubrectangleQueries(rectangle)
 * obj.updateSubrectangle(row1,col1,row2,col2,newValue)
 * var param_2 = obj.getValue(row,col)
 */
```

![](https://i.imgur.com/q3w882b.png)
