<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code> and an integer <code>k</code>. In an operation, you can choose an element and multiply it by <code>2</code>.</p>

<p>Return <em>the maximum possible value of </em><code>nums[0] | nums[1] | ... | nums[n - 1]</code> <em>that can be obtained after applying the operation on nums at most </em><code>k</code><em> times</em>.</p>

<p>Note that <code>a | b</code> denotes the <strong>bitwise or</strong> between two integers <code>a</code> and <code>b</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [12,9], k = 1
<strong>Output:</strong> 30
<strong>Explanation:</strong> If we apply the operation to index 1, our new array nums will be equal to [12,18]. Thus, we return the bitwise or of 12 and 18, which is 30.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [8,1,2], k = 2
<strong>Output:</strong> 35
<strong>Explanation:</strong> If we apply the operation twice on index 0, we yield a new array of [32,1,2]. Thus, we return 32|1|2 = 35.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
	<li><code>1 &lt;= k &lt;= 15</code></li>
</ul>

class SparseTable:
    def __init__(self, data, fn=lambda x,y : x|y):
        """
        Initialize the Sparse Table with the given data array and function.
        
        :param data: List[int] - The input array for which the Sparse Table is to be constructed.
        :param fn: function - The function to be used for range queries (e.g., min, max, gcd).
        """
        self.n = len(data)
        self.data = data
        self.fn = fn
        
        # Precompute log values
        self.log = [0] * (self.n + 1)
        for i in range(2, self.n + 1):
            self.log[i] = self.log[i // 2] + 1

        self.k = self.log[self.n] + 1
        self.st = [[0] * self.k for _ in range(self.n)]
        
        self._build()

    def _build(self):
        """
        Build the Sparse Table using the given function.
        """
        for i in range(self.n):
            self.st[i][0] = self.data[i]

        j = 1
        while (1 << j) <= self.n:
            i = 0
            while (i + (1 << j) - 1) < self.n:
                self.st[i][j] = self.fn(self.st[i][j - 1], self.st[i + (1 << (j - 1))][j - 1])
                i += 1
            j += 1

    def query(self, l, r):
        """
        Query the function value in the range [l, r].
        
        :param l: int - Left index of the range (inclusive).
        :param r: int - Right index of the range (inclusive).
        :return: int - The function value in the range [l, r].
        """
        j = self.log[r - l + 1]
        return self.fn(self.st[l][j], self.st[r - (1 << j) + 1][j])
class Solution:
    def maximumOr(self, nums: List[int], k: int) -> int:
        N = len(nums)
        st = SparseTable(nums)
        d = {}
        for i in range(N):
            d[i] = 0
            if i-1>=0:
                d[i]|=st.query(0,i-1)
            if i+1<N:
                d[i]|=st.query(i+1,N-1)
        return max(d[i]|(nums[i]<<k) for i in range(N))
            
1314