Binary Matrix after flipping submatrices in given range for Q queries | Function to flip a submatrices ; Boundaries of the submatrix ; Iterate over the submatrix ; Check for 1 or 0 and flip accordingly ; Function to perform the queries ; Driver Code ; Function call
def manipulation ( matrix , q ) : NEW_LINE INDENT x1 , y1 , x2 , y2 = q NEW_LINE for i in range ( x1 - 1 , x2 ) : NEW_LINE INDENT for j in range ( y1 - 1 , y2 ) : NEW_LINE INDENT if matrix [ i ] [ j ] : NEW_LINE INDENT matrix [ i ] [ j ] = 0 NEW_LINE DEDENT else : NEW_LINE INDENT matrix [ i ] [ j ] = 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT def queries_fxn ( matrix , queries ) : NEW_LINE INDENT for q in queries : NEW_LINE INDENT manipulation ( matrix , q ) NEW_LINE DEDENT DEDENT matrix = [ [ 0 , 1 , 0 ] , [ 1 , 1 , 0 ] ] NEW_LINE queries = [ [ 1 , 1 , 2 , 3 ] , [ 1 , 1 , 1 , 1 ] , [ 1 , 2 , 2 , 3 ] ] NEW_LINE queries_fxn ( matrix , queries ) NEW_LINE print ( matrix ) NEW_LINE