output_description: For each query with T_i=2, print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N Q
      A_1 A_2 \cdots A_N
      T_1 L_1 R_1
      T_2 L_2 R_2
      \vdots
      T_Q L_Q R_Q
attempt: I = [int(_) for _ in open(0).read().split()]
  N, Q = I[:2]
  A = I[2 : 2 + N]
  T = I[2 + N :: 3]
  L = I[3 + N :: 3]
  R = I[4 + N :: 3]
  
  
  class LazySegmentTree:
      def __init__(self, array, f, g, h, ti, ei):
          """
          Parameters
          ----------
          array : list
              to construct segment tree from
          f : func
              binary operation of the monoid
              T x T -> T
              T is dat
          g : func
              binary operation of the monoid
              T x E -> T
              T is dat, E is laz
          h : func
              binary operation of the monoid
              E x E -> T
              E is laz
          ti : T
              identity element of T
          ei : E
              identity element of E
          """
          self.f = f
          self.g = g
          self.h = h
          self.ti = ti
          self.ei = ei
          self.height = height = len(array).bit_length()
          self.n = n = 2**height
          self.dat = dat = [ti] * n + array + [ti] * (n - len(array))
          self.laz = [ei] * (2 * n)
          for i in range(n - 1, 0, -1):  # build
              dat[i] = f(dat[i << 1], dat[i << 1 | 1])
  
      def reflect(self, k):
          dat = self.dat
          ei = self.ei
          laz = self.laz
          g = self.g
          return self.dat[k] if laz[k] is ei else g(dat[k], laz[k])
  
      def evaluate(self, k):
          laz = self.laz
          ei = self.ei
          reflect = self.reflect
          dat = self.dat
          h = self.h
          if laz[k] is ei:
              return
          laz[(k << 1) | 0] = h(laz[(k << 1) | 0], laz[k])
          laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k])
          dat[k] = reflect(k)
          laz[k] = ei
  
      def thrust(self, k):
          height = self.height
          evaluate = self.evaluate
          for i in range(height, 0, -1):
              evaluate(k >> i)
  
      def recalc(self, k):
          dat = self.dat
          reflect = self.reflect
          f = self.f
          while k:
              k >>= 1
              dat[k] = f(reflect((k << 1) | 0), reflect((k << 1) | 1))
  
      def update(self, a, b, x):  # set value at position [a, b) (0-indexed)
          thrust = self.thrust
          n = self.n
          h = self.h
          laz = self.laz
          recalc = self.recalc
          a += n
          b += n - 1
          l = a
          r = b + 1
          thrust(a)
          thrust(b)
          while l < r:
              if l & 1:
                  laz[l] = h(laz[l], x)
                  l += 1
              if r & 1:
                  r -= 1
                  laz[r] = h(laz[r], x)
              l >>= 1
              r >>= 1
          recalc(a)
          recalc(b)
  
      def set_val(self, a, x):
          n = self.n
          thrust = self.thrust
          dat = self.dat
          laz = self.laz
          recalc = self.recalc
          ei = self.ei
          a += n
          thrust(a)
          dat[a] = x
          laz[a] = ei
          recalc(a)
  
      def query(self, a, b):  # result on interval [a, b) (0-indexed)
          f = self.f
          ti = self.ti
          n = self.n
          thrust = self.thrust
          reflect = self.reflect
          a += n
          b += n - 1
          thrust(a)
          thrust(b)
          l = a
          r = b + 1
          vl = vr = ti
          while l < r:
              if l & 1:
                  vl = f(vl, reflect(l))
                  l += 1
              if r & 1:
                  r -= 1
                  vr = f(reflect(r), vr)
              l >>= 1
              r >>= 1
          return f(vl, vr)
  
  
  # general linear functions
  array = [(0, 0, 0)] + [(0, 1, 0) if a else (1, 0, 0) for a in A]
  f = lambda a, b: (a[0] + b[0], a[1] + b[1], a[2] + b[2] + a[1] * b[0])
  
  
  def g(a, b):
      if b == -1:
          x = a[1]
          y = a[0]
          z = (x + y) * (x + y - 1) // 2 - x * (x - 1) // 2 - y * (y - 1) // 2 - a[2]
          return (x, y, z)
      else:
          return a
  
  
  h = lambda a, b: a * b
  ti = (0, 0, 0)
  ei = 1
  # b[0] * (a[0] * x + a[1]) + b[1]
  # = b[0] * a[0] * x + (b[0] * a[1] + b[1])
  
  LST = LazySegmentTree(array=array, ti=ti, ei=ei, f=f, g=g, h=h)
  
  for t, l, r in zip(T, L, R):
      r += 1
      if t == 1:
          LST.update(l, r, -1)
      else:
          print(LST.query(l, r)[2])
  
problem_description: Statement
  
  You are given a binary array A=(A_1,A_2,\cdots,A_N) of length N.
  
  Process Q queries of the following types. The i-th query is represented by
  three integers T_i,L_i,R_i.
  
    * T_i=1: Replace the value of A_j with 1-A_j for each L_i \leq j \leq R_i.
    * T_i=2: Calculate the inversion(*) of the array A_{L_i},A_{L_i+1},\cdots,A_{R_i}．
  
  Note：The inversion of the array x_1,x_2,\cdots,x_k is the number of the pair
  of integers i,j with 1 \leq i < j \leq k, x_i > x_j.
samples: [{"input": "5 5\n    0 1 0 0 1\n    2 1 5\n    1 3 4\n    2 2 5\n    1 1 3\n    2 1 2", "output": "2\n    0\n    1\n    \n\n  * First query: Print 2, which is the inversion of (A_1,A_2,A_3,A_4,A_5)=(0,1,0,0,1).\n  * Second query: Replace the value of A_3 and A_4 with 1 and 1, respectively.\n  * Third query: Print 0, which is the inversion of (A_2,A_3,A_4,A_5)=(1,1,1,1).\n  * Fourth query: Replace the value of A_1, A_2 and A_4 with 1, 0 and 0, respectively.\n  * Fifth query: Print 1, which is the inversion of (A_1,A_2)=(1,0)."}]