[Python] Segment tree and sliding window/two pointers
Explanation:\n1. Create a segment tree to calculate the bitwise OR for the intervals in the array.\n2. Starting from the end of the array and traversing back, w
**Explanation:**\n1. Create a segment tree to calculate the bitwise OR for the intervals in the array.\n2. Starting from the end of the array and traversing back, we can apply the sliding window/two pointers method. \n3. Whenever we satisfy the condition: (bitwise OR between[left, right-1] == bitwise OR between[left, right]), that means we don\'t need the num at the right pointer to get a larger bitwise OR value. We can then greedily shrink the window by decreasing the right pointer to get a smaller length of the subarray.\n\n```\nclass SegTree:\n\n    def __init__(self, nums):\n        self.n = n = len(nums)\n        self.tree = [0] * (2 * n)\n        for i in range(n):\n            self.tree[i + n] = nums[i]\n        for i in range(n-1, 0, -1):\n            self.tree[i] = self.tree[2 * i] | self.tree[2 * i + 1]\n        \n    def orRange(self, left, right):\n        left += self.n\n        right += self.n + 1\n        orRes = 0\n        while left < right:\n            if left % 2 == 1:\n                orRes |= self.tree[left]\n                left += 1\n            \n            if right % 2 == 1:\n                right -= 1\n                orRes |= self.tree[right]\n                \n            left //= 2\n            right //= 2\n        return orRes\n\nclass Solution:\n    def smallestSubarrays(self, nums: List[int]) -> List[int]:\n        \n        segtree = SegTree(nums)\n        \n        ans = [1] * len(nums)\n        l = len(nums) - 1\n        r = len(nums) - 1\n        \n        while l >= 0:\n\n            while r > l and segtree.orRange(l, r-1) == segtree.orRange(l, r):\n                r -= 1\n                \n            ans[l] = r - l + 1\n            l -= 1\n            \n        return ans\n```
['Tree', 'Sliding Window']