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++14 (judge verdict: Memory Limit Exceeded)

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
typedef int V;
// NV=3010101 -> 38MB
#define NV 6010101
#define def 2147483647
struct PersistentSegmentTree { //[L,R)
    V comp(V a, V b) { return min(a,b); }




    // -- template ---------------------
    struct S { int l, r; V x; } v[NV];
    int cnt = 1, n = -1;
    void init(int _n) {
        n = _n;
        rep(i, 0, NV) v[i].l = v[i].r = 0, v[i].x = def;
    }
    void add(int &root, int l, int r, int i, int val) {
        v[cnt] = v[root];
        root = cnt++;

        if (l + 1 == r) {
            v[root].x += val;
            return;
        }

        int mi = (l + r) / 2;
        if (i < mi) add(v[root].l, l, mi, i, val);
        else add(v[root].r, mi, r, i, val);

        v[root].x = comp(v[v[root].l].x, v[v[root].r].x);
    }
    void add(int &root, int i, int val) {
        assert(0 < n);
        add(root, 0, n, i, val); }
    void update(int &root, int l, int r, int i, int val) {
        v[cnt] = v[root];
        root = cnt++;

        if (l + 1 == r) {
            v[root].x = val;
            return;
        }

        int mi = (l + r) / 2;
        if (i < mi) update(v[root].l, l, mi, i, val);
        else update(v[root].r, mi, r, i, val);

        v[root].x = comp(v[v[root].l].x, v[v[root].r].x);
    }
    void update(int &root, int i, int val) {
        assert(0 < n);
        update(root, 0, n, i, val);
    }
    int query(int a, int b, int l, int r, int k) {
        assert(0 < n);
        if (v[b].x - v[a].x < k) return -2;
        if (l + 1 == r) return l;
        int mi = (l + r) / 2;
        int re = query(v[a].l, v[b].l, l, mi, k); // v[0] always 0
        if (re < 0) re = query(v[a].r, v[b].r, mi, r, k);
        return re;
    }

    int allget(int root) {
        return v[root].x;
    }


    // todo
    int get(int root, int l, int r, int L, int R) {
        if (l >= r) return def;
        if (l == L && r == R) return v[root].x;
        int mi = (L + R) / 2;
        V le = get(v[root].l, max(l, L), min(r, mi), L, mi);
        V ri = get(v[root].r, max(l, mi), min(r, R), mi, R);
        return comp(le, ri);
    }
    int get(int root, int l, int r) {
        return get(root, l, r, 0, n);
    }
};
/*---------------------------------------------------------------------------------------------------
????????????????????????????????? ??§?????§  
??????????????? ??§?????§ ???????´<_??? ?????? Welcome to My Coding Space!
???????????? ??? ?´_???`??????/??? ???i     
?????????????????????????????? ???  |???|     
????????? /?????? /??£??£??£??£/??????|  
??? ???_(__??????/???    ???/ .| .|????????????  
??? ????????????/????????????/??????u??????  
---------------------------------------------------------------------------------------------------*/













int N, Q;
PersistentSegmentTree pst;
int root = 0;
//---------------------------------------------------------------------------------------------------
void _main() {
    pst.init(101010);

    cin >> N >> Q;
    rep(_, 0, Q) {
        int c, x, y; cin >> c >> x >> y;

        if (c == 0) pst.update(root, x, y);
        else printf("%d\n", pst.get(root, x, y + 1));
    }
}