class Matrix: def __init__(self, data): self.data = data self.rows = len(data) self.cols = len(data[0]) if data else 0 def __add__(self, other): result = [[self.data[i][j] + other.data[i][j] for j in range(self.cols)] for i in range(self.rows)] return Matrix(result) def __mul__(self, other): result = [[sum(self.data[i][k] * other.data[k][j] for k in range(self.cols)) for j in range(other.cols)] for i in range(self.rows)] return Matrix(result) class SegmentTree: def __init__(self, data, func=min): self.n = len(data) self.func = func self.tree = [None] * (2 * self.n) for i in range(self.n): self.tree[self.n + i] = data[i] for i in range(self.n - 1, 0, -1): self.tree[i] = self.func(self.tree[2 * i], self.tree[2 * i + 1]) def update(self, index, value): pos = index + self.n self.tree[pos] = value while pos > 1: pos //= 2 self.tree[pos] = self.func(self.tree[2 * pos], self.tree[2 * pos + 1]) def query(self, left, right): res = self.default left += self.n right += self.n while left < right: if left % 2: res = self.func(self.tree[left], res) left += 1 if right % 2: right -= 1 res = self.func(res, self.tree[right]) left //= 2 right //= 2 return res N, Q = map(int, input().split()) S = input() matrices = [] matrices.append(Matrix([[1, 1, 0], [0, 1, 0], [0, 0, 1]])) matrices.append(Matrix([[1, 0, 0], [1, 1, 1], [0, 0, 1]])) matrices.append(Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])) matrice_array = [matrices(int(S[i])) for i in range(N)] segment_tree = SegmentTree(matrice_array, func=lambda a, b: a * b) for _ in range(Q): q, l, r = input().split() if q == '1': for i in range(l - 1, r): segment_tree.update(i, matrices[2]) else: result = segment_tree.query(l - 1, r) print(result.data[1][2] + result.data[2][2])