Subrectangle Queries
You can implement the SubrectangleQueries
class by storing the given rectangle as a class member and then implementing the two methods according to the provided descriptions.
updateSubrectangle(int row1, int col1, int row2, int col2, int newValue)
: This method updates all values within the specified subrectangle with the new value.getValue(int row, int col)
: This method returns the value at the given coordinate within the rectangle.
Here’s the code:
|
|
In the updateSubrectangle
method, we use nested loops to iterate over all the elements in the specified subrectangle and update them to the new value. In the getValue
method, we simply return the value at the specified coordinates.