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)

#include <cstdio>
#include <climits>
#include <algorithm>
using namespace std;

// Abstract Lazy Segment Tree (????±?????±?????????¶?????°???????????¨)
const int SIZE = 1 << 17; // 2^17 = 131072
template<typename T>
struct lazysegtree {
    // ?????????????????????
    T node[2*SIZE], lazy[2*SIZE], I;
    bool need_upd[2*SIZE];

    // ????????¬????????§??? (update, query ??? 2 ???????????????)
    // update function ??????????????????????????¢????????????
    // upd_f(X, Y, l, r) -> ????????? [l, r) ??§???????????????????????? X ??? Y ????????????
    // lazy ???????????? update ??¨??????????????? 1 ??????????????¨?????°?????????
    T (*upd_f)(T, T, int, int), (*qry_f)(T, T);

    // ???????????¨?????????????????????????????¨?????? node ??¨ lazy ??????????????§?????????
    lazysegtree(T (*op1)(T, T, int, int), T (*op2)(T, T), T X) {
        upd_f = op1;
        qry_f = op2;
        I = X;
        fill(lazy, lazy+2*SIZE, I);
        fill(node, node+2*SIZE, I);
        fill(need_upd, need_upd+2*SIZE, false);
    }

    void lazy_eval(int k, int l, int r) {
        if(!need_upd[k]) return;
        node[k] = upd_f(node[k], lazy[k], l, r);
        if(r - l > 1) {
            lazy[2*k+1] = upd_f(lazy[2*k+1], lazy[k], 0, 1);
            lazy[2*k+2] = upd_f(lazy[2*k+2], lazy[k], 0, 1);
            need_upd[2*k+1] = need_upd[2*k+2] = true;
        }
        lazy[k] = I;
        need_upd[k] = false;
    }

    // ???????????? [a, b) ??????????????? val ??????????????????
    // (upd_f ?????¨????????????)
    void update(int a, int b, T val, int l=0, int r=SIZE, int k=0) {
        lazy_eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = upd_f(lazy[k], val, 0, 1);
            need_upd[k] = true;
            lazy_eval(k, l, r);
        }
        else {
            int mid = (l + r) / 2;
            update(a, b, val, l, mid, 2*k+1);
            update(a, b, val, mid, r, 2*k+2);
            node[k] = qry_f(node[2*k+1], node[2*k+2]);
        }
    }

    // ???????????? [a, b) ?????????????????¨???????????????
    // (qry_f ?????¨????????????)
    T query(int a, int b, int l=0, int r=SIZE, int k=0) {
        lazy_eval(k, l, r);
        if(b <= l || r <= a) return I;
        if(a <= l && r <= b) return node[k];
        int mid = (l + r) / 2;
        T vl = query(a, b, l, mid, 2*k+1);
        T vr = query(a, b, mid, r, 2*k+2);
        return qry_f(vl, vr);
    }
};

// [[???????????????]]
// update ??¨??¨ query ??¨?????¢??°??¨????????? (??¢??°????????????????????????????????????????????????) ?????¨???????????£?¨???????
// ??????????????¨???update ??¨?????¢??°??? upd ??§???query ??¨?????¢??°??? fnd ??§??????????????? INT_MAX

typedef long long int ll;
ll upd(ll a, ll b, int l, int r) {return b;}
ll fnd(ll a, ll b) {return min(a, b);}
lazysegtree<ll> seg(upd, fnd, INT_MAX);

int main() {
    int N, Q; scanf("%d%d", &N, &Q);
    while(Q--) {
        int c, x, y; scanf("%d%d%d", &c, &x, &y);
        if(c == 0) {
            seg.update(x, x+1, y);
        }
        else {
            printf("%lld\n", seg.query(x, y+1));
        }
    }
    return 0;
}