Count distinct Bitwise OR of all Subarrays | C ++ implementation of the above approach ; function to calculate count of distinct bitwise OR of all subarrays . ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int distintBitwiseOR ( int arr [ ] , int n ) { unordered_set < int > ans , prev ; for ( int i = 0 ; i < n ; i ++ ) { unordered_set < int > ne ; for ( auto x : prev ) ne . insert ( arr [ i ] x ) ; ne . insert ( arr [ i ] ) ; for ( auto x : ne ) ans . insert ( x ) ; prev = ne ; } return ans . size ( ) ; } int main ( ) { int n = 3 ; int arr [ ] = { 1 , 2 , 4 } ; cout << distintBitwiseOR ( arr , n ) ; return 0 ; }