C++ | SEGMENT TREE | BINARY SEARCH
PLEASE DO UPVOTE IF U FIND MY SOLUTION HELPFUL :)\n\nclass Solution {\n    vector<int>seg_tree;\n    void build(int node,int s,int e,vector<int>& nums)\n    {\n
**PLEASE DO UPVOTE IF U FIND MY SOLUTION HELPFUL :)**\n```\nclass Solution {\n    vector<int>seg_tree;\n    void build(int node,int s,int e,vector<int>& nums)\n    {\n        if(s>e)return;\n        if(s==e){seg_tree[node]=nums[s];return;}\n        int mid=s+(e-s)/2;\n        build(2*node,s,mid,nums);\n        build(2*node+1,mid+1,e,nums);\n        seg_tree[node]=seg_tree[2*node]|seg_tree[2*node+1];\n    }\n    int range_OR(int node,int s,int e,int l,int r)\n    {\n        if(s>e||e<l||s>r)\n            return 0;\n        if(s>=l&&e<=r||s==e)return seg_tree[node];\n        \n        int mid=s+(e-s)/2;\n        int left_OR=range_OR(2*node,s,mid,l,r);\n        int right_OR=range_OR(2*node+1,mid+1,e,l,r);\n        return left_OR|right_OR;\n    }\npublic:\n    vector<int> smallestSubarrays(vector<int>& nums) {\n        int n=nums.size();\n        vector<int>v(n);\n        v[n-1]=nums[n-1];\n        for(int i=n-2;i>=0;i--)v[i]=nums[i]|v[i+1];\n        \n        seg_tree=vector<int>(4*n);\n        build(1,0,n-1,nums);\n        vector<int>res(n);\n        for(int i=0;i<n;i++)\n        {\n            int max_OR=v[i];\n            int lo=i,hi=n-1;\n            while(lo<=hi)\n            {\n                int mid=lo+(hi-lo)/2;\n                int rangeOR=range_OR(1,0,n-1,i,mid);\n                if(rangeOR<max_OR)\n                    lo=mid+1;\n                else\n                    hi=mid-1;\n            }\n            res[i]=lo-i+1;\n        }\n        return res;\n    }\n};\n```
['Tree', 'Binary Tree']