module agc60
 implicit none
contains
 subroutine agc60a(a,x,y)
  integer(8),intent(in)::x,y
  integer(8),intent(inout)::a(:)
  integer(8)::ia
  do ia=x,y
   a(ia)=1-a(ia)
  end do
 end subroutine agc60a
 function agc60b(a,x,y)result(ans)
  integer(8),intent(in)::a(:),x,y
  integer(8)::ib,c,ic,ans
  c=0
  do ib=x,y
   if(a(ib)==1)then
    do ic=ib+1,y
     if(a(ic)==0)then
      c=c+1
     end if
    end do
   end if
  end do
  ans=c
 end function agc60b
end module agc60

program abc60
 use agc60
 implicit none
 integer(8),allocatable::a(:)
 integer(8)::N,Q,ia,ib,p,x,y
 read(*,*)N,Q
 allocate(a(N))
 read(*,*)(a(ia),ia=1,N)
 do ib=1,Q
  read(*,*)p,x,y
  if(p==1)then
   call agc60a(a,x,y)
  else
   print'(i0)',agc60b(a,x,y)
  end if
 end do
 deallocate(a)
end program abc60