text: Bitwise OR of bitwise AND of all possible non | Java program for the above approach ; Function to find the Bitwise OR of Bitwise AND of all possible subarrays after performing the every query ; Traversing each pair of the query ; Stores the Bitwise OR ; Updating the array ; Find the Bitwise OR of new updated array ; Print the ans ; Driver Code
code: import java . io . * ; class GFG { static void performQuery ( int arr [ ] , int Q [ ] [ ] ) { for ( int i = 0 ; i < Q . length ; i ++ ) { int or = 0 ; int x = Q [ i ] [ 0 ] ; arr [ x - 1 ] = Q [ i ] [ 1 ] ; for ( int j = 0 ; j < arr . length ; j ++ ) { or = or | arr [ j ] ; } System . out . print ( or + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 } ; int Q [ ] [ ] = { { 1 , 4 } , { 3 , 0 } } ; performQuery ( arr , Q ) ; } }