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)

use std::io::{Read, Write};

struct CustomIO<'a> {
    sin: ::std::io::Bytes<::std::io::StdinLock<'a>>,
    sout: ::std::io::StdoutLock<'a>,
    buf: [u8; 20],
}
impl<'a> CustomIO<'a> {
    pub fn new(
        sin: ::std::io::Bytes<::std::io::StdinLock<'a>>,
        sout: ::std::io::StdoutLock<'a>,
    ) -> Self {
        CustomIO::<'a> {
            sin: sin,
            sout: sout,
            buf: [0u8; 20],
        }
    }

    pub fn readu32(&mut self) -> u32 {
        self.sin
            .by_ref()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .fold(0u32, |a, x| a * 10 + (x as u8 - b'0') as u32)
    }

    pub fn readu64(&mut self) -> u64 {
        self.sin
            .by_ref()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .fold(0u64, |a, x| a * 10 + (x as u8 - b'0') as u64)
    }

    pub fn readusize(&mut self) -> usize {
        self.sin
            .by_ref()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .fold(0usize, |a, x| a * 10 + (x as u8 - b'0') as usize)
    }

    pub fn writeu32(&mut self, mut v: u32) {
        let mut i = 20usize;
        while v != 0u32 {
            i -= 1usize;
            self.buf[i] = (v % 10) as u8 + b'0';
            v /= 10;
        }
        if i == 20usize {
            i = 19usize;
            self.buf[19] = b'0';
        }
        let _ = self.sout.write(&self.buf[i..20]);
    }

    pub fn writeu64(&mut self, mut v: u64) {
        let mut i = 20usize;
        while v != 0u64 {
            i -= 1usize;
            self.buf[i] = (v % 10) as u8 + b'0';
            v /= 10;
        }
        if i == 20usize {
            i = 19usize;
            self.buf[19] = b'0';
        }
        let _ = self.sout.write(&self.buf[i..20]);
    }

    pub fn writeusize(&mut self, mut v: usize) {
        let mut i = 20usize;
        while v != 0usize {
            i -= 1usize;
            self.buf[i] = (v % 10) as u8 + b'0';
            v /= 10;
        }
        if i == 20usize {
            i = 19usize;
            self.buf[19] = b'0';
        }
        let _ = self.sout.write(&self.buf[i..20]);
    }

    pub fn endl(&mut self){
        let _ = self.sout.write(&[b'\n']);
    }
}

pub struct SegmentTree<T>
where
    T: ::math::algebra::Magma,
{
    c: ::std::vec::Vec<<T as ::math::algebra::Magma>::T>,
}
impl<T> SegmentTree<T>
where
    T: ::math::algebra::Magma + ::math::algebra::Identity,
    <T as ::math::algebra::Magma>::T: ::std::clone::Clone,
{
    pub fn new(len: usize) -> Self {
        Self {
            c: vec![<T as ::math::algebra::Identity>::identity(); len << 1u32],
        }
    }
}
impl<T> SegmentTree<T>
where
    T: ::math::algebra::Magma,
{
    pub fn is_empty(&self) -> bool {
        self.c.is_empty()
    }

    pub fn len(&self) -> usize {
        self.c.len() >> 1u32
    }
}
impl<T> SegmentTree<T>
where
    T: ::math::algebra::Magma + ::math::algebra::Associativity + ::math::algebra::Identity,
{
    pub fn fold(&self, range: ::std::ops::Range<usize>) -> <T as ::math::algebra::Magma>::T {
        let (mut first, mut last) = (range.start + self.len(), range.end + self.len());
        let (mut ret_l, mut ret_r) = (
            <T as ::math::algebra::Identity>::identity(),
            <T as ::math::algebra::Identity>::identity(),
        );
        while first < last {
            if (first & 1usize) != 0usize {
                ret_l = <T as ::math::algebra::Magma>::operation(&ret_l, &self.c[first]);
                first += 1usize;
            }
            if (last & 1usize) != 0usize {
                ret_r = <T as ::math::algebra::Magma>::operation(&ret_r, &self.c[last - 1usize]);
            }
            first >>= 1u32;
            last >>= 1u32;
        }
        <T as ::math::algebra::Magma>::operation(&ret_l, &ret_r)
    }
}
impl<T> SegmentTree<T>
where
    T: ::math::algebra::Magma + ::math::algebra::Associativity,
{
    pub fn update<F>(&mut self, mut index: usize, f: F)
    where
        F: ::std::ops::FnOnce(&<T as ::math::algebra::Magma>::T)
            -> <T as ::math::algebra::Magma>::T,
    {
        index += self.len();
        self.c[index] = f(&self.c[index]);
        index >>= 1u32;
        while index != 0usize {
            self.c[index] = <T as ::math::algebra::Magma>::operation(
                &self.c[index << 1u32],
                &self.c[index << 1u32 | 1usize],
            );
            index >>= 1u32;
        }
    }

    pub fn set(&mut self, index: usize, value: <T as ::math::algebra::Magma>::T) {
        self.update(index, move |_| value)
    }
}
impl<T> ::std::ops::Index<usize> for SegmentTree<T>
where
    T: ::math::algebra::Magma,
{
    type Output = <T as ::math::algebra::Magma>::T;
    fn index(&self, index: usize) -> &Self::Output {
        &self.c[index + self.len()]
    }
}

pub mod math {
    pub mod algebra {
        pub trait Magma {
            type T;
            fn operation(&Self::T, &Self::T) -> Self::T;
        }
        pub trait Associativity: Magma {}
        pub trait Commutativity: Magma {}
        pub trait Idempotency: Magma {}
        pub trait Identity: Magma {
            fn identity() -> Self::T;
        }
    }
}

struct RMQ {}
impl ::math::algebra::Magma for RMQ {
    type T = u32;
    fn operation(l: &u32, r: &u32) -> u32 {
        ::std::cmp::min(*l, *r)
    }
}
impl ::math::algebra::Identity for RMQ {
    fn identity() -> u32 {
        2147483647u32
    }
}
impl ::math::algebra::Associativity for RMQ {}

fn main() {
    let stdin = ::std::io::stdin();
    let stdout = ::std::io::stdout();
    let mut cio = CustomIO::new(stdin.lock().bytes(), stdout.lock());

    let n = cio.readusize();
    let q = cio.readusize();

    let mut seg = SegmentTree::<RMQ>::new(n);

    for _ in 0..q {
        let com = cio.readu32();
        let x = cio.readusize();
        if com == 0u32 {
            let y = cio.readu32();
            seg.set(x, y);
        } else {
            let y = cio.readusize() + 1usize;
            cio.writeu32(seg.fold(x..y));
            cio.endl();
        }
    }
}