OverKill | Used Segment Trees | Binary Search | C++
\n#include <bits/stdc++.h>\nusing namespace std;\n\nclass segTree {\n  private:\n    vector<int> tree, arr;\n    int n;\n\n    void build(int index, int low, in
```\n#include <bits/stdc++.h>\nusing namespace std;\n\nclass segTree {\n  private:\n    vector<int> tree, arr;\n    int n;\n\n    void build(int index, int low, int high)\n    {\n        if (low == high) {\n            tree[index] = arr[low];\n            return;\n        }\n\n        int mid = (low + high) >> 1;\n        int left = 2 * index + 1;\n        int right = 2 * index + 2;\n\n        build(left, low, mid);\n        build(right, mid + 1, high);\n\n        tree[index] = tree[left] | tree[right];\n    }\n\n    void updateUtil(int index, int low, int high, int pos, int val)\n    {\n        if (low == high) {\n            tree[index] = val;\n            return;\n        }\n\n        int mid = (low + high) >> 1;\n        int left = 2 * index + 1;\n        int right = 2 * index + 2;\n\n        if (pos <= mid)\n            updateUtil(left, low, mid, pos, val);\n        else\n            updateUtil(right, mid + 1, high, pos, val);\n\n        tree[index] = tree[left] + tree[right];\n    }\n\n    int queryUtil(int index, int low, int high, int qLeft, int qRight)\n    {\n        // (qLeft, qRight) [low, high] (qLeft, qRight)\n\n        if (qRight < low || high < qLeft) {\n            return 0;\n        }\n\n        // (qLeft (low, right) qRight)\n        if (qLeft <= low and high <= qRight) {\n            return tree[index];\n        }\n\n        int mid = (low + high) >> 1;\n        int left = 2 * index + 1;\n        int right = 2 * index + 2;\n\n        int LeftSum = queryUtil(left, low, mid, qLeft, qRight);\n        int RightSum = queryUtil(right, mid + 1, high, qLeft, qRight);\n\n        return LeftSum | RightSum;\n    }\n\n  public:\n    segTree(vector<int> &nums)\n    {\n        this->n = nums.size();\n        this->arr = nums;\n        tree.resize(4 * n + 1);\n\n        build(0, 0, n - 1);\n    }\n\n    void update(int index, int val)\n    {\n        updateUtil(0, 0, n - 1, index, val);\n    }\n\n    int query(int left, int right)\n    {\n        return queryUtil(0, 0, n - 1, left, right);\n    }\n};\nclass Solution {\npublic:\n    vector<int> smallestSubarrays(vector<int>& nums) {\n        int n = nums.size();\n        segTree sgt(nums);\n        \n        vector<int> ans;\n        for(int i = 0; i < n; i++) {\n            int l = i, r = n - 1;\n            int mx = sgt.query(i, n - 1);\n            \n            int ind = n - 1;\n            while(l <= r) {\n                int mid = (l + r) / 2;\n                \n                if ((nums[i] | sgt.query(i, mid)) == mx) {\n                    ind = mid;\n                    r = mid - 1;\n                }\n                else {\n                    l = mid + 1;\n                }\n            }\n            \n            ans.push_back(ind - i + 1);\n        }\n        \n        return ans;\n    }\n};\n```\n![image](https://assets.leetcode.com/users/images/7cf7a50a-0e63-4fa5-8a65-5dd03c532ca5_1663483306.2416594.jpeg)\n\n\n
['Tree', 'Binary Tree']