<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than </em><code>k</code>.</p>

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

<pre>
<strong>Input:</strong> nums = [10,5,2,6], k = 100
<strong>Output:</strong> 8
<strong>Explanation:</strong> The 8 subarrays that have product less than 100 are:
[10], [5], [2], [6], [10, 5], [5, 2], [2, 6], [5, 2, 6]
Note that [10, 5, 2] is not included as the product of 100 is not strictly less than k.
</pre>

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

<pre>
<strong>Input:</strong> nums = [1,2,3], k = 0
<strong>Output:</strong> 0
</pre>

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

<ul>
	<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= 1000</code></li>
	<li><code>0 &lt;= k &lt;= 10<sup>6</sup></code></li>
</ul>

from math import log2, ceil
# class Segtree:
#     def __init__(self, data):
#         self.data = data
#         self.length = len(data)
#         self.makeTree()
#     def makeTree(self):
#         levels = (int)(ceil(log2(self.length)))
#         self.tree = [None] * (2*(2**levels)-1)
#         self.makeTreeHelp(0,self.length-1, 0)
#     def makeTreeHelp(self,s,e,idx):
#         if s > e:
#             return
#         if s == e:
#             self.tree[idx] = self.data[s]
#             return
#         mid = (s+e)//2
#         left = self.makeTreeHelp(s, mid, idx*2+1)
#         right = self.makeTreeHelp(mid+1,e,idx*2+2)
#         print(self.tree)
#         self.tree[idx] = left*right


class Solution:
    def numSubarrayProductLessThanK(self, nums: List[int], k: int) -> int:
        arrs = 0
       # q = collections.deque()
        l = 0
        prod = 1
        for r in range(len(nums)):
            prod*=nums[r]
            while l <= r and prod >=k:
                prod/= nums[l]
                l+=1
            arrs+= (r-l+1)
        return arrs

            


        
19300