Count of Ks in the Array for a given range of indices after array updates for Q queries | Function to perform all the queries ; Stores the count of 0 s ; Count the number of 0 s for query of type 1 ; Update the array element for query of type 2 ; Driver Code
function performQueries ( n , q , k , arr , query ) { = for ( let i = 1 ; i <= q ; i ++ ) { let count = 0 ; if ( query [ i - 1 ] [ 0 ] == 1 ) { for ( let j = query [ i - 1 ] [ 1 ] ; j <= query [ i - 1 ] [ 2 ] ; j ++ ) { if ( arr [ j ] == k ) count ++ ; } document . write ( count + " " ) ; } else { arr [ query [ i - 1 ] [ 1 ] ] = query [ i - 1 ] [ 2 ] ; } } } let arr = [ 9 , 5 , 7 , 6 , 9 , 0 , 0 , 0 , 0 , 5 , 6 , 7 , 3 , 9 , 0 , 7 , 0 , 9 , 0 ] ; let Q = 5 ; let query = [ [ 1 , 5 , 14 ] , [ 2 , 6 , 1 ] , [ 1 , 0 , 8 ] , [ 2 , 13 , 0 ] , [ 1 , 6 , 18 ] , ] ; let N = arr . length ; let K = 0 ; performQueries ( N , Q , K , arr , query ) ;