---
# System prepended metadata

title: Untitled

---

#### 1476. Subrectangle Queries
=======

```javascript=
var SubrectangleQueries = function(rectangle) {
    this.arr = new Array();
    this.rows = rectangle.length
    this.cols = rectangle[0].length
    for(var key in rectangle) {
        for(var key2 in rectangle[key]) {
            this.arr.push(rectangle[key][key2])
        }
    }
    console.log(this.arr, 'SubrectangleQueries')
};

/** 
 * @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) {
    console.log(row1 != row2 && col1 == col2, 46)
    if(row1 != row2 && col1 == col2) {
        for(i = row1 ; i <= row2; i++) {
            this.arr[i*this.cols + col1] = newValue
        }
    } else {
        start = row1*this.cols + col1
        end = row2*this.cols + col2
        this.arr = this.arr.map(function(row, key) {
            if( start <= key && key <= end)
                return newValue
            return row
        })
    }
    console.log(this.arr, 'updateSubrectangle');
    return null; 
};

/** 
 * @param {number} row 
 * @param {number} col
 * @return {number}
 */
SubrectangleQueries.prototype.getValue = function(row, col) {
    console.log(this.arr[row*this.cols + col], 'getValue');
    return this.arr[row*this.cols + col]
};
```

```javascript=
/**
 * @param {number[][]} rectangle
 */

var SubrectangleQueries = function(rectangle) {
    this.arr = rectangle;
    this.rows = rectangle.length
    this.cols = rectangle[0].length
    console.log(this.arr, 'SubrectangleQueries')
};

/** 
 * @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) {
    if(row1 >= this.rows || row2 >= this.rows || col1 >= this.cols || col2 >= this.cols)
            return;
    for(i = row1 ; i <= row2; i++) {
        for(j = col1 ; j<= col2; j++ ){
            this.arr[i][j] = newValue
        }
    }
    console.log(this.arr, 'updateSubrectangle');
    return null; 
};

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



test
 ["SubrectangleQueries","getValue","updateSubrectangle","getValue","getValue","updateSubrectangle","getValue","getValue"]
[[[[1,2,1],[4,3,4],[3,2,1],[1,1,1]]],[0,2],[0,0,3,2,5],[0,2],[3,1],[3,0,3,2,10],[3,1],[0,2]]
["SubrectangleQueries","updateSubrectangle","getValue","getValue","updateSubrectangle","getValue","getValue"]
[[[[3,9,4],[5,6,10]]],[1,1,1,1,5],[1,0],[1,0],[0,0,1,0,6],[1,0],[0,1]]
["SubrectangleQueries","updateSubrectangle","getValue","updateSubrectangle","updateSubrectangle","updateSubrectangle","getValue"]
[[[[9,9],[4,7],[9,6]]],[1,0,2,1,9],[2,0],[0,1,1,1,9],[1,1,2,1,1],[1,0,1,0,9],[0,1]]



["SubrectangleQueries","getValue","getValue","getValue","updateSubrectangle","updateSubrectangle","getValue","updateSubrectangle","updateSubrectangle","updateSubrectangle","getValue","updateSubrectangle","updateSubrectangle","updateSubrectangle","getValue","updateSubrectangle","getValue","updateSubrectangle","getValue","updateSubrectangle","getValue","getValue","updateSubrectangle","updateSubrectangle","updateSubrectangle","getValue","updateSubrectangle","getValue","getValue","getValue","updateSubrectangle","getValue","updateSubrectangle","getValue","getValue","getValue","updateSubrectangle","updateSubrectangle"]
[
    [
        [
            [464,692,376,558,935,968,194,818,494,744,75,834,861,1000,263,418,207],
            [9,765,545,789,390,527,898,499,79,414,631,904,523,816,593,599,436],
            [42,361,872,470,7,195,984,307,713,708,658,6,554,123,842,310,525],
            [909,765,324,995,796,557,661,586,565,290,539,422,556,963,839,950,977],
            [531,419,618,646,596,316,464,310,135,519,455,601,144,564,792,998,167],
            [259,652,10,435,754,678,580,38,378,431,412,289,959,675,917,770,686],
            [19,921,93,948,93,867,5,393,276,476,279,816,801,382,652,768,873],
            [493,788,345,398,468,823,120,496,364,149,426,152,19,177,834,267,377],
            [879,131,604,806,295,973,423,265,962,527,295,758,431,708,281,444,344],
            [796,936,498,221,733,850,504,973,995,412,734,436,94,66,133,212,990],
            [154,235,748,27,106,260,160,492,794,976,102,409,666,741,192,855,4],
            [92,438,627,978,53,563,224,548,433,356,49,969,668,993,949,106,753],
            [567,696,430,855,688,759,122,272,701,286,184,492,825,813,722,879,49],
            [806,220,694,660,90,888,400,127,685,459,302,699,521,510,927,403,119],
            [621,875,491,109,153,396,629,928,720,207,172,534,264,427,762,910,958],
            [550,296,890,505,649,917,830,558,935,220,808,778,639,346,882,498,106],
            [9,776,747,674,356,949,907,992,726,274,58,554,641,451,308,779,926],
            [863,104,235,521,282,277,724,253,422,152,134,263,200,418,575,646,613],
            [926,984,60,546,855,624,522,153,969,424,277,287,492,713,314,274,504],
            [220,511,377,614,482,248,347,181,621,778,186,757,902,595,711,462,548],
            [154,60,517,334,542,707,139,661,780,832,913,219,323,638,506,492,338],
            [122,131,909,144,716,263,231,91,651,552,849,720,52,577,177,702,119],
            [232,577,205,516,582,676,906,316,433,336,5,793,21,842,313,842,631],
            [226,87,761,230,287,698,641,882,350,276,616,737,531,389,24,125,338],
            [356,143,117,257,921,789,147,698,588,43,356,80,95,743,106,308,325]
        ]
    ],
    [8,16],
    [11,0],
    [4,12],
    [23,3,23,13,337], //updateSubrectangle false
    [0,10,16,10,361], //updateSubrectangle true
    [19,8],
    [2,16,23,16,578], //updateSubrectangle true
    [17,9,23,12,648], //updateSubrectangle false
    [17,1,19,4,180], //updateSubrectangle false
    [6,13],
    [17,8,17,16,278], //updateSubrectangle
    [15,12,17,12,763], //updateSubrectangle
    [2,11,22,15,569], //updateSubrectangle
    [19,9], // error
    [21,4,22,5,936],
    [21,6],
    [24,11,24,13,164],
    [12,14],
    [3,4,22,8,303],
    [17,0],
    [12,3],
    [0,13,24,16,283],
    [13,14,19,14,102],
    [24,0,24,1,852],
    [18,4],
    [17,11,21,14,840],
    [19,7],
    [17,11],[3,1],[13,11,24,13,674],[19,13],[12,9,17,14,452],[20,16],[1,10],[16,5],[10,3,22,12,23],[6,5,18,11,734]]