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(dead_code)]
#![allow(unused_imports)]
#![allow(unused_variables)]

use std::cmp::{max, min};

const INF: i32 = 1001001001;
const LNF: i64 = 1001001001001001001;
const MOD: i32 = 1000000007;

macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
      let mut iter = $s.split_whitespace();
      input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
      let s = {
          use std::io::Read;
          let mut s = String::new();
          std::io::stdin().read_to_string(&mut s).unwrap();
          s
      };
      let mut iter = s.split_whitespace();
      input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
      let $var = read_value!($iter, $t);
      input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
      ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
      (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
      read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
      read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
      $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    n: usize,
    q: usize,
    line: [(i32, usize, usize); q],
  }
  let mut st = SegmentTree::new(n, 2147483647);
  for i in 0..q {
    let (com, x, y) = line[i];
    if com == 0 {
      st.update(x, y as i32);
    } else {
      println!("{}", st.query(x, y + 1));
    }
  }
}

struct SegmentTree {
  v: Vec<i32>,
  e: i32,
  n: usize,
}

impl SegmentTree {
  fn new(size: usize, e: i32) -> Self {
    let mut n = 1;
    while n < size {
      n <<= 1;
    }
    let v: Vec<i32> = vec![e; n * 2];
    SegmentTree { v, e, n }
  }
  fn set(&mut self, k: usize, x: i32) {
    self.v[k + self.n] = x;
  }
  fn build(&mut self) {
    for i in (1..self.n).rev() {
      self.v[i] = min(self.v[i * 2 + 0], self.v[i * 2 + 1]);
    }
  }
  fn update(&mut self, mut k: usize, x: i32) {
    self.v[k + self.n] = x;
    k += self.n;
    while (k >> 1) > 0 {
      k >>= 1;
      self.v[k] = min(self.v[k * 2 + 0], self.v[k * 2 + 1]);
    }
  }
  fn query(&self, mut a: usize, mut b: usize) -> i32 {
    let mut l = self.e;
    let mut r = self.e;
    a += self.n;
    b += self.n;
    while a < b {
      if a & 1 == 1 {
        l = min(l, self.v[a]);
        a += 1;
      }
      if b & 1 == 1 {
        b -= 1;
        r = min(self.v[b], r);
      }
      a >>= 1;
      b >>= 1;
    }
    min(l, r)
  }
  fn reset(&mut self, k: usize) {
    self.update(k, 2147483647);
  }
}