human
Find Number of Even cells in a Zero Matrix after Q queries | Function to find the number of even cell in a 2D matrix.
Maintain two arrays , one for rows operation and one for column operation.
Increment operation on row [ i ].
Increment operation on col [ i ].
Count odd and even values in both arrays and multiply them.
Count of rows having even numbers.
Count of rows having odd numbers.
Count of columns having even numbers.
Count of columns having odd numbers.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to find Number of Even cells in a Zero Matrix after Q queries and the other steps required.
 def findNumberOfEvenCells ( n , q , size ) :
	row = [ 0 ] * n ;
	col = [ 0 ] * n
	for i in range ( size ) :
		x = q [ i ] [ 0 ] ;
		y = q [ i ] [ 1 ] ;
		row [ x - 1 ] += 1 ;
		col [ y - 1 ] += 1 ;
	r1 = 0 ;
	r2 = 0 ;
	c1 = 0 ;
	c2 = 0 ;
	for i in range ( n ) :
		if ( row [ i ] % 2 == 0 ) :
			r1 += 1 ;
		if ( row [ i ] % 2 == 1 ) :
			r2 += 1 ;
		if ( col [ i ] % 2 == 0 ) :
			c1 += 1 ;
		if ( col [ i ] % 2 == 1 ) :
			c2 += 1 ;
	count = r1 * c1 + r2 * c2 ;
	return count ;
if __name__ == " _ _ main _ _ " :
	n = 2 ;
	q = [ [ 1 , 1 ] , [ 1 , 2 ] , [ 2 , 1 ] ] ;
	size = len ( q ) ;
	print ( findNumberOfEvenCells ( n , q , size ) ) ;