Function to solve each query
function SolveQuery ( arr , n , Q ) { let x ; for ( let i = 0 ; i < Q . length ; i ++ ) { if ( Q [ i ] [ 0 ] == 1 ) { x = getCount ( arr , n , Q [ i ] [ 1 ] [ 0 ] , Q [ i ] [ 1 ] [ 1 ] ) ; document . write ( x + " " ) ; } else { setElement ( arr , n , Q [ i ] [ 1 ] [ 0 ] , Q [ i ] [ 1 ] [ 1 ] ) ; } } }