Segment Tree Solution
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
    struct SegmentTree {
    int n;
    vector<int> tree;

    // Constructor: builds the tree from the given data vector.
    SegmentTree(const vector<int>& data) {
        n = data.size();
        tree.resize(4 * n, 0);
        build(data, 1, 0, n - 1);
    }

    // Recursively build the segment tree.
    void build(const vector<int>& data, int node, int start, int end) {
        if(start == end) {
            tree[node] = data[start]; // Leaf node holds the original array element.
        } else {
            int mid = (start + end) / 2;
            build(data, 2 * node, start, mid);
            build(data, 2 * node + 1, mid + 1, end);
            // Internal node holds the bitwise OR of its two children.
            tree[node] = tree[2 * node] | tree[2 * node + 1];
        }
    }

    // Utility function to query the tree for range [l, r].
    int query(int node, int start, int end, int l, int r) {
        // If current segment is completely outside the query range.
        if(r < start || end < l)
            return 0; // 0 is the identity for bitwise OR.
        // If current segment is completely inside the query range.
        if(l <= start && end <= r)
            return tree[node];
        // Otherwise, query both children and combine the results.
        int mid = (start + end) / 2;
        int left_query = query(2 * node, start, mid, l, r);
        int right_query = query(2 * node + 1, mid + 1, end, l, r);
        return left_query | right_query;
    }

    // Public query interface: returns the bitwise OR of elements in the range [l, r].
    int query(int l, int r) {
        return query(1, 0, n - 1, l, r);
    }
};
public:
    vector<int> smallestSubarrays(vector<int>& nums) {
        SegmentTree segTree(nums);
        int n=nums.size();
        vector<int> suff(n);
        suff[n-1]=nums[n-1];
        for(int i=n-2;i>=0;--i){
            suff[i]=suff[i+1]|nums[i];
        }
        vector<int> ans(n);
        for(int i=0;i<n;++i){
            int exp=suff[i];
            int low=1,high=n-i;
            while(low<=high){
                int mid=(low+high)/2;
                if(segTree.query(i, i+mid-1)<exp){
                    low=mid+1;
                }
                else{
                    high=mid-1;
                }
            }
            ans[i]=low;
        }
        return ans;
        
    }
};
```
['Array', 'Binary Search', 'Sliding Window', 'C++']