use std::io::{stdin, Read, StdinLock}; use std::str::FromStr; use std::iter::FromIterator; fn main() { let cin = stdin(); let mut scan = Scanner::new(cin.lock()); let n = scan.read::(); let q = scan.read::(); let a = scan.readn::(n); let mut segtree = SegTree::new(a, 1i64<<60, std::cmp::min); for _ in 0..q { let op = scan.read::(); let l = scan.read::()-1; let r = scan.read::()-1; if op == 1 { let ltmp = segtree.get_one(l).0; let rtmp = segtree.get_one(r).0; segtree.set(l, rtmp); segtree.set(r, ltmp); } else { let (_, i) = segtree.get(l..r+1); println!("{}", i+1); } } } use std::ops::Range; #[allow(dead_code)] fn contains(p: &Range, q: &Range) -> bool { p.start <= q.start && q.end <= p.end } #[allow(dead_code)] fn separates(p: &Range, q: &Range) -> bool { p.end <= q.start || q.end <= p.start } #[allow(dead_code)] fn size(p: &Range) -> usize { p.end - p.start } #[allow(dead_code)] struct SegTree<'a> { node: Vec<(i64, usize)>, zero: i64, op: Box (i64, usize) + 'a>, n: usize, } #[allow(dead_code)] impl <'a> SegTree<'a> { fn new(v: Vec, zero: i64, op: B) -> SegTree<'a> where B: Fn((i64, usize), (i64, usize)) -> (i64, usize) + 'a { let size = v.len(); let mut n = 1usize; while n < size {n *= 2} let mut node = vec![(zero, 0); 2*n-1]; for i in 0..size {node[i+n-1] = (v[i], i)} for i in (0..n - 1).rev() {node[i] = op(node[2*i+1], node[2*i+2])} SegTree {node: node, zero: zero, op: Box::new(op), n: n} } fn set(&mut self, mut x: usize, value: i64) { let y = x; x += self.n - 1; self.node[x] = (value, y); while x > 0 { x = (x - 1) / 2; self.node[x] = (self.op)(self.node[2*x+1], self.node[2*x+2]); } } fn get_one(&self, i: usize) -> (i64, usize) {self.getrec(i..i+1, 0, 0..self.n)} fn get(&self, query: Range) -> (i64, usize) {self.getrec(query, 0, 0..self.n)} fn getrec(&self, query: Range, k: usize, range: Range) -> (i64, usize) { if separates(&query, &range) {return (self.zero, 0)} if contains(&query, &range) {return self.node[k]} let vl = self.getrec(query.clone(), 2*k+1, range.start..(range.start + range.end)/2); let vr = self.getrec(query.clone(), 2*k+2, (range.start + range.end)/2..range.end); (self.op)(vl, vr) } } // region template #[allow(dead_code)] fn iu(i: isize) -> usize { i as usize } #[allow(dead_code)] fn ui(i: usize) -> isize { i as isize } #[allow(dead_code, deprecated)] fn join(slice: &[T], sep: &str) -> String { let strings = slice.iter().map(|t| format!("{}", t)).collect::>(); strings.connect(sep) } #[allow(dead_code)] fn arr<'a, S, T>(n: usize, mut f: S) -> Vec where S: FnMut(usize) -> T + 'a { (0..n).map(|i| f(i)).collect::>() } #[allow(dead_code)] fn alt(v: Vec) -> T where T: FromIterator { v.into_iter().collect::() } #[allow(dead_code)] fn dup(v: &[S]) -> T where T: FromIterator, S: Clone { v.iter().cloned().collect::() } struct Scanner<'a> { cin: StdinLock<'a>, } #[allow(dead_code)] impl<'a> Scanner<'a> { fn new(cin: StdinLock<'a>) -> Scanner<'a> { Scanner { cin: cin } } fn read1(&mut self) -> Option { let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect::(); token.parse::().ok() } fn read(&mut self) -> T { self.read1().unwrap() } fn readn(&mut self, n: usize) -> Vec { (0..n).map(|_| self.read::()).collect() } fn chars(&mut self) -> Vec { self.read::().chars().collect() } } // endregion