<p>You are given two <strong>0-indexed</strong> arrays <code>nums1</code> and <code>nums2</code> and a 2D array <code>queries</code> of queries. There are three types of queries:</p>

<ol>
	<li>For a query of type 1, <code>queries[i]&nbsp;= [1, l, r]</code>. Flip the values from <code>0</code> to <code>1</code> and from <code>1</code> to <code>0</code> in <code>nums1</code>&nbsp;from index <code>l</code> to index <code>r</code>. Both <code>l</code> and <code>r</code> are <strong>0-indexed</strong>.</li>
	<li>For a query of type 2, <code>queries[i]&nbsp;= [2, p, 0]</code>. For every index <code>0 &lt;= i &lt; n</code>, set&nbsp;<code>nums2[i] =&nbsp;nums2[i]&nbsp;+ nums1[i]&nbsp;* p</code>.</li>
	<li>For a query of type 3, <code>queries[i]&nbsp;= [3, 0, 0]</code>. Find the sum of the elements in <code>nums2</code>.</li>
</ol>

<p>Return <em>an array containing all the answers to the third type&nbsp;queries.</em></p>

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

<pre>
<strong>Input:</strong> nums1 = [1,0,1], nums2 = [0,0,0], queries = [[1,1,1],[2,1,0],[3,0,0]]
<strong>Output:</strong> [3]
<strong>Explanation:</strong> After the first query nums1 becomes [1,1,1]. After the second query, nums2 becomes [1,1,1], so the answer to the third query is 3. Thus, [3] is returned.
</pre>

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

<pre>
<strong>Input:</strong> nums1 = [1], nums2 = [5], queries = [[2,0,0],[3,0,0]]
<strong>Output:</strong> [5]
<strong>Explanation:</strong> After the first query, nums2 remains [5], so the answer to the second query is 5. Thus, [5] is returned.
</pre>

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

<ul>
	<li><code>1 &lt;= nums1.length,nums2.length &lt;= 10<sup>5</sup></code></li>
	<li><code>nums1.length = nums2.length</code></li>
	<li><code>1 &lt;= queries.length &lt;= 10<sup>5</sup></code></li>
	<li><code><font face="monospace">queries[i].length = 3</font></code></li>
	<li><code><font face="monospace">0 &lt;= l &lt;= r &lt;= nums1.length - 1</font></code></li>
	<li><code><font face="monospace">0 &lt;= p &lt;= 10<sup>6</sup></font></code></li>
	<li><code>0 &lt;= nums1[i] &lt;= 1</code></li>
	<li><code>0 &lt;= nums2[i] &lt;= 10<sup>9</sup></code></li>
</ul>

class LazySegTree:
    def __init__(self, arr, l, r):
        self.left, self.right = None, None
        mid = (l + r)//2
        self.lazy = 1
        self.l, self.r = l, r
        if l == r:
            self.sum = arr[l]
        else:
            self.left = LazySegTree(arr, l, mid)
            self.right = LazySegTree(arr, mid + 1, r)
            self.sum = self.left.sum + self.right.sum
    def lazyprop(self):
        if self.lazy == -1:
            if self.left:
                self.left.lazy *= -1
            if self.right:
                self.right.lazy *= -1
            self.sum = self.r- self.l + 1 - self.sum
            self.lazy = 1
            # print(self.sum, 'new sum')
    def update(self, l, r):
        if l <= self.l and self.r <= r:
            # print(self.l, self.r)
            self.lazy *= -1
            self.lazyprop()
        else:
            self.lazyprop()
            if self.intersect(l, r):
                self.sum = 0
                if self.left:
                    # print(self.left.l, self.left.r, 'updating here')
                    self.left.update(l, r)
                    self.sum += self.left.sum
                if self.right:
                    # print(self.right.l, self.right.r, 'updating here 2')
                    self.right.update(l, r)
                    self.sum += self.right.sum
    def intersect(self, l, r):
        if self.r < l or self.l > r:
            return False
        return True
    def query(self, l, r):
        if l <= self.l and self.r <= r:
            if self.lazy == -1:
                self.sum = (self.r - self.l + 1) - self.sum
                if self.left:
                    self.left.lazy *= -1
                if self.right:
                    self.right.lazy *= -1
                self.lazy = 1
            return self.sum
        else:
            ans = 0
            if self.left and self.left.intersect(l, r):
                ans += self.left.query(l, r)
            if self.right and self.right.intersect(l, r):
                ans += self.right.query(l, r)
            return ans

class Solution:
    def handleQuery(self, nums1: List[int], nums2: List[int], queries: List[List[int]]) -> List[int]:
        segtree = LazySegTree(nums1, 0, len(nums1)-1)
        ans = sum(nums2)
        out = []
        for i in queries:
            # print(segtree.query(0, len(nums1)-1), 'cursum')

            if i[0] == 1:
                segtree.update(i[1], i[2])
            elif i[0] == 2:
                ans += i[1] * segtree.query(0, len(nums1)-1)
            else:
                out.append(ans)
        return out
70000