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 Rust (judge verdict: Accepted)

#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stderr, stdin, stdout, BufWriter, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::{i64, u64, usize};
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , [ $ t : tt ] ) => { { let len = read_value ! ( $ next , usize ) ; ( 0 .. len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[allow(unused_macros)]
macro_rules! dbg {
    ($($a:expr),*) => {
        writeln!(&mut stderr(), concat!($(stringify!($a), " = {:?}, "),*), $($a),*).unwrap();
    }
}

trait Monoid {
    type T: Clone;
    fn id() -> Self::T;
    fn op(a: &Self::T, b: &Self::T) -> Self::T;
}
struct SegmentTree<M: Monoid> {
    n_leaf: usize,
    data: Vec<M::T>,
}
impl<M: Monoid> SegmentTree<M> {
    #[allow(dead_code)]
    fn new(_n: usize) -> SegmentTree<M> {
        let mut n = 1;
        while n < _n {
            n *= 2;
        }
        SegmentTree {
            n_leaf: n,
            data: vec![M::id(); 2 * n - 1],
        }
    }
    #[allow(dead_code)]
    fn update(&mut self, i: usize, val: M::T) {
        let mut i = i + self.n_leaf - 1;
        self.data[i] = val;
        while i > 0 {
            i = (i - 1) / 2;
            self.data[i] = M::op(&self.data[2 * i + 1], &self.data[2 * i + 2]);
        }
    }
    #[allow(dead_code)]
    fn _query(&self, left: usize, right: usize, i: usize, l: usize, r: usize) -> M::T {
        if right <= l || r <= left {
            M::id()
        } else if left <= l && r <= right {
            self.data[i].clone()
        } else {
            let child_left = self._query(left, right, i * 2 + 1, l, (l + r) / 2);
            let child_right = self._query(left, right, i * 2 + 2, (l + r) / 2, r);
            M::op(&child_left, &child_right)
        }
    }
    #[allow(dead_code)]
    fn query(&self, left: usize, right: usize) -> M::T {
        self._query(left, right, 0, 0, self.n_leaf)
    }
}
impl<M: Monoid> std::ops::Index<usize> for SegmentTree<M> {
    type Output = M::T;
    fn index(&self, index: usize) -> &Self::Output {
        &self.data[index + self.n_leaf - 1]
    }
}

struct MinI64;
impl Monoid for MinI64 {
    type T = i64;
    fn id() -> Self::T {
        (1 << 31) - 1
    }
    fn op(a: &Self::T, b: &Self::T) -> Self::T {
        std::cmp::min(*a, *b)
    }
}

#[allow(non_snake_case)]
#[allow(dead_code)]
fn main() {
    input!{
        n: usize,
        q: usize,
        query: [(usize, usize, usize); q],
    }
    let mut seg: SegmentTree<MinI64> = SegmentTree::new(n);
    for (com, x, y) in query {
        if com == 0 {
            seg.update(x, y as i64);
        } else {
            println!("{}", seg.query(x, y + 1));
        }
    }
}