C++/Python, solution with explanation
Traverse nums reversely,\nuse an array to record which index is the latest 1 bit appears in 32 bits.\nAnd find furthest index of 1 bit, the length of subarray i
Traverse nums reversely,\nuse an array to record which index is the latest 1 bit appears in 32 bits.\nAnd find furthest index of 1 bit, the length of subarray is furthest index - i + 1.\n![image](https://assets.leetcode.com/users/images/6545636b-145c-47fd-a46d-ec6493794a2b_1693816614.9771085.png)\n\ntc isO(32n), sc is O(32).\n\n### python\n```python\nclass Solution:\n    def smallestSubarrays(self, nums: List[int]) -> List[int]:\n        cloest = [-1] * 32\n        ans = [0] * len(nums)\n        for i in range(len(nums)-1,-1,-1):\n            furthest = i\n            for j in range(32):\n                if nums[i] >> j & 1:\n                    cloest[j] = i\n                if cloest[j] > furthest: furthest = cloest[j]\n            ans[i] = furthest - i + 1\n        return ans\n```\n\n### c++\n```cpp\nclass Solution {\npublic:\n    vector<int> smallestSubarrays(vector<int>& nums) {\n        int closest [32] {0};\n        vector<int> ans (nums.size());\n        for (int i = nums.size() - 1, furthest; i >= 0; i-=1) {\n            furthest = i;\n            for (int j = 0; j < 32; j+=1) {\n                if (nums[i] >> j & 1)\n                    closest[j] = i;\n                if (closest[j] > furthest) furthest = closest[j];\n            }\n            ans[i] = furthest - i + 1;\n        }\n        return ans;\n    }\n};\n```
['C', 'Python']