class RMaxQ:

    

    __slots__ = ["n", "data"]

    

    def __init__(self, li):

        self.n = len(li)

        self.data = li*2

        for i in range(self.n - 1, 0, -1):

            self.data[i] = max(self.data[2*i], self.data[2*i+1])

    

    def update(self, i, a):

        i += self.n

        self.data[i] = a

        while i > 1:

            i //= 2

            self.data[i] = max(self.data[2*i], self.data[2*i+1])

    

    def add(self, i, a):

        i += self.n

        self.data[i] += a

        while i > 1:

            i //= 2

            self.data[i] = max(self.data[2*i], self.data[2*i+1])

    

    def fold(self, l, r):

        l += self.n

        r += self.n

        res = 0

        while l < r:

            if l % 2:

                res = max(self.data[l], res)

                l += 1

            if r % 2:

                r -= 1

                res = max(res, self.data[r])

            l //= 2

            r //= 2

        return res



n, q = list(map(int, input().split()))

A = list(map(int, input().split()))

seg = RMaxQ(A)

for _ in range(q):

    t, x, v = list(map(int, input().split()))

    x -= 1

    if t == 1:

        seg.update(x, v)

    elif t == 2:

        print((seg.fold(x, v)))

    else:

        ng = x

        ok = n+1

        while ok - ng > 1:

            mid = (ok+ng)//2

            if seg.fold(x, mid) >= v:

                ok = mid

            else:

                ng = mid

        print(ok)
class RMaxQ:

    

    __slots__ = ["n", "data"]

    

    def __init__(self, li):

        self.n = len(li)

        self.data = li*2

        for i in range(self.n - 1, 0, -1):

            self.data[i] = max(self.data[2*i], self.data[2*i+1])

    

    def update(self, i, a):

        i += self.n

        self.data[i] = a

        while i > 1:

            i //= 2

            self.data[i] = max(self.data[2*i], self.data[2*i+1])

    

    def add(self, i, a):

        i += self.n

        self.data[i] += a

        while i > 1:

            i //= 2

            self.data[i] = max(self.data[2*i], self.data[2*i+1])

    

    def fold(self, l, r):

        l += self.n

        r += self.n

        res = 0

        while l < r:

            if l % 2:

                res = max(self.data[l], res)

                l += 1

            if r % 2:

                r -= 1

                res = max(res, self.data[r])

            l //= 2

            r //= 2

        return res



import sys

input = sys.stdin.buffer.readline

n, q = list(map(int, input().split()))

A = list(map(int, input().split()))

seg = RMaxQ(A)

for _ in range(q):

    t, x, v = list(map(int, input().split()))

    x -= 1

    if t == 1:

        seg.update(x, v)

    elif t == 2:

        print((seg.fold(x, v)))

    else:

        ng = x

        ok = n+1

        while ok - ng > 1:

            mid = (ok+ng)//2

            if seg.fold(x, mid) >= v:

                ok = mid

            else:

                ng = mid

        print(ok)
class RMaxQ:
    __slots__ = ["n", "data"]

    def __init__(self, li):
        self.n = len(li)
        self.data = li * 2
        for i in range(self.n - 1, 0, -1):
            self.data[i] = max(self.data[2 * i], self.data[2 * i + 1])

    def update(self, i, a):
        i += self.n
        self.data[i] = a
        while i > 1:
            i //= 2
            self.data[i] = max(self.data[2 * i], self.data[2 * i + 1])

    def add(self, i, a):
        i += self.n
        self.data[i] += a
        while i > 1:
            i //= 2
            self.data[i] = max(self.data[2 * i], self.data[2 * i + 1])

    def fold(self, l, r):
        l += self.n
        r += self.n
        res = 0
        while l < r:
            if l % 2:
                res = max(self.data[l], res)
                l += 1
            if r % 2:
                r -= 1
                res = max(res, self.data[r])
            l //= 2
            r //= 2
        return res


n, q = list(map(int, input().split()))
A = list(map(int, input().split()))
seg = RMaxQ(A)
for _ in range(q):
    t, x, v = list(map(int, input().split()))
    x -= 1
    if t == 1:
        seg.update(x, v)
    elif t == 2:
        print((seg.fold(x, v)))
    else:
        ng = x
        ok = n + 1
        while ok - ng > 1:
            mid = (ok + ng) // 2
            if seg.fold(x, mid) >= v:
                ok = mid
            else:
                ng = mid
        print(ok)

class RMaxQ:
    __slots__ = ["n", "data"]

    def __init__(self, li):
        self.n = len(li)
        self.data = li * 2
        for i in range(self.n - 1, 0, -1):
            self.data[i] = max(self.data[2 * i], self.data[2 * i + 1])

    def update(self, i, a):
        i += self.n
        self.data[i] = a
        while i > 1:
            i //= 2
            self.data[i] = max(self.data[2 * i], self.data[2 * i + 1])

    def add(self, i, a):
        i += self.n
        self.data[i] += a
        while i > 1:
            i //= 2
            self.data[i] = max(self.data[2 * i], self.data[2 * i + 1])

    def fold(self, l, r):
        l += self.n
        r += self.n
        res = 0
        while l < r:
            if l % 2:
                res = max(self.data[l], res)
                l += 1
            if r % 2:
                r -= 1
                res = max(res, self.data[r])
            l //= 2
            r //= 2
        return res


import sys

input = sys.stdin.buffer.readline
n, q = list(map(int, input().split()))
A = list(map(int, input().split()))
seg = RMaxQ(A)
for _ in range(q):
    t, x, v = list(map(int, input().split()))
    x -= 1
    if t == 1:
        seg.update(x, v)
    elif t == 2:
        print((seg.fold(x, v)))
    else:
        ng = x
        ok = n + 1
        while ok - ng > 1:
            mid = (ok + ng) // 2
            if seg.fold(x, mid) >= v:
                ok = mid
            else:
                ng = mid
        print(ok)

+import sys + +input = sys.stdin.buffer.readline