Problem:
Range Minimum Query (RMQ)

Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations:

find(s, t): report the minimum element in as, as+1, . . . ,at.

update(i, x): change ai to x.

Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.

Input

n q
com0 x0 y0
com1 x1 y1
...
comq−1 xq−1 yq−1

In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).

Output

For each find operation, print the minimum element.

Constraints

1 ≤ n ≤ 100000

1 ≤ q ≤ 100000

If comi is 0, then 0 ≤ xi < n, 0 ≤ yi < 231-1.

If comi is 1, then 0 ≤ xi < n, 0 ≤ yi < n.

Sample Input 1

3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2

Sample Output 1

1
2

Sample Input 2

1 3
1 0 0
0 0 5
1 0 0

Sample Output 2

2147483647
5

Solution in C# (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class SegmentTree<T> {
    public int Size;
    public T[] Node;
    public Func<T, T, T> Calc;
    T Def;

    public SegmentTree(int n, T[] init, T def, Func<T, T, T> calc) {
        Calc = calc;
        Def = def;
        Size = 1;
        while(Size < n) Size *= 2;
        Node = new T[2 * Size - 1];
        for(int i = 0; i < init.Length; i++) {
            Node[(Size - 1) + i] = init[i];
        }
        for(int i = init.Length; i < Size; i++) {
            Node[(Size - 1) + i] = Def;
        }
        for(int i = (Size - 1) - 1; 0 <= i; i--) {
            Node[i] = Calc(Node[2 * i + 1], Node[2 * i + 2]);
        }
    }

    public void Update(int index, T value) {
        int pos = (Size - 1) + index;
        Node[pos] = value;
        while(0 < pos) {
            pos = (pos - 1) / 2;
            Node[pos] = Calc(Node[2 * pos + 1], Node[2 * pos + 2]);
        }
    }

    public T GetRange(int index, int length) {
        return GetRange(index, length, 0, 0, Size);
    }

    public T GetRange(int index, int length, int k, int l, int r) {
        if(r <= index || index + length <= l) {
            return Def;
        }
        if(index <= l && r <= index + length) {
            return Node[k];
        }
        T vl = GetRange(index, length, k * 2 + 1, l, (l + r) / 2);
        T vr = GetRange(index, length, k * 2 + 2, (l + r) / 2, r);
        return Calc(vl, vr);
    }
}

class A {
    static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static void Main(string[] args) {
        int n, q;
        Input(out n, out q);
        SegmentTree<int> seg = new SegmentTree<int>(n, new int[0], int.MaxValue, (a, b) => Math.Min(a, b));
        for(int i = 0; i < q; i++) {
            int t, x, y;
            Input(out t, out x, out y);
            if(t == 0) {
                seg.Update(x, y);
            } else {
                Print(seg.GetRange(x, y - x + 1));
            }
        }
        Out.Flush();
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void Inputs<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
    static void Print<T>(T s) => Out.WriteLine(s);
    static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s));
    static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e));
}