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::cmp::min;
use std::io;
use std::io::prelude::*;
use std::iter::repeat;

struct MinSegTree {
    n: usize,
    nodes: Vec<i32>,
}

impl MinSegTree {
    fn init(n: usize) -> MinSegTree {
        let n = 1 << f64::log2(n as f64).ceil() as usize;
        let mut ret = MinSegTree {
            n,
            nodes: repeat(std::i32::MAX).take(2 * n - 1).collect(),
        };
        for i in (0..(n - 1)).rev() {
            ret.update1(i);
        }
        ret
    }

    fn update1(&mut self, idx: usize) {
        self.nodes[idx] = min(self.nodes[2 * idx + 1], self.nodes[2 * idx + 2]);
    }

    fn update_rec(&mut self, idx: usize) {
        self.update1(idx);
        if idx > 0 {
            self.update_rec((idx - 1) / 2);
        }
    }

    fn update(&mut self, i: usize, x: i32) {
        let ni = self.n + i - 1;
        self.nodes[ni] = x;
        if self.n > 1 {
            self.update_rec((ni - 1) / 2);
        }
    }

    fn find(&self, i: usize, j: usize, ni: usize, l: usize, r: usize) -> i32 {
        if i <= l && r <= j {
            self.nodes[ni]
        } else if r <= i || j <= l {
            std::i32::MAX
        } else {
            min(
                self.find(i, j, 2 * ni + 1, l, (l + r) / 2),
                self.find(i, j, 2 * ni + 2, (l + r) / 2, r),
            )
        }
    }
}

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();

    let line0 = lines.next().unwrap().unwrap();
    let n = line0.split_whitespace().next().unwrap().parse().unwrap();

    let mut mst = MinSegTree::init(n);

    for l in lines.map(Result::unwrap) {
        let mut words = l.split_whitespace();
        let com = words.next().unwrap().parse().unwrap();
        let x = words.next().unwrap().parse().unwrap();
        let y: usize = words.next().unwrap().parse().unwrap();
        match com {
            0 => mst.update(x, y as i32),
            1 => println!("{}", mst.find(x, y + 1, 0, 0, mst.n)),
            _ => (),
        }
    }
}