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)*} }; } 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)*} }; } 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::>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::>() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; } use std::fmt::Debug; struct SegTree { data: Vec, size: usize, zero: T, mapped: fn(&T, &T) -> T, } impl SegTree { /* 8 elements 1 2 3 4 5 6 7 8 9 A B C D E F <- <- */ fn new(size: usize, zero: T, mapped: fn(&T, &T) -> T) -> SegTree { let mut data = vec![]; for _ in 0..2 * size + 1 { data.push(zero.clone()) } SegTree { data: data, size: size, zero: zero, mapped: mapped, } } fn fold(&self, l: usize, r: usize) -> T { let mut fl = self.zero.clone(); let mut fr = self.zero.clone(); let mut l = l + self.size; let mut r = r + self.size; /* 1: 2: 3:0 4:1 5:2 6:X 7:X */ while l < r { if l & 1 == 1 { fl = (self.mapped)(&self.data[l], &fl); l += 1; } if r & 1 == 1 { r -= 1; fr = (self.mapped)(&fr, &self.data[r]); } l >>= 1; r >>= 1; } (self.mapped)(&fl, &fr) } fn update(&mut self, i: usize, x: T) { let mut i = i + self.size; self.data[i] = x; while i > 1 { i >>= 1; self.data[i] = (self.mapped)(&self.data[i << 1], &self.data[(i << 1) + 1]) } } fn select(&self, i: usize) -> &T { &self.data[i + self.size] } } fn main() { input! { n: usize, q:usize, query: [(usize, i64, i64); q] } use std::cmp; let inf = (1 << 31) - 1; let mut seg = SegTree::new(n, inf, |x, y| cmp::min(*x, *y)); for (com, x, y) in query { if com == 1 { seg.update(x as usize, y); } else { println!("{}", seg.fold(x as usize, y as usize)); } } }