Problem:
RMQ and RUQ

Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:

update(s, t, x): change as, as+1, ..., at to x.

find(s, t): report the minimum element in as, as+1, ..., at.

Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.

Input

n q
query1
query2
:
queryq

In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:

0 s t x

or

1 s t

The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(s, t).

Output

For each find operation, print the minimum value.

Constraints

1 ≤ n ≤ 100000

1 ≤ q ≤ 100000

0 ≤ s ≤ t < n

0 ≤ x < 231−1

Sample Input 1

3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0 2
1 1 2

Sample Output 1

1
2

Sample Input 2

1 3
1 0 0
0 0 0 5
1 0 0

Sample Output 2

2147483647
5

Solution in Rust (judge verdict: Accepted)

#![allow(non_snake_case)]

#[allow(unused_macros)]
macro_rules! debug {
    ( $x:ident [ $i:expr ] ) => {
        if cfg!(debug_assertions) {
            println!("{}[{}] = {:?}", stringify!($x), $i, $x[$i]);
        }
    };
    ( $x:ident [ $i:expr ][ $j:expr ] ) => {
        if cfg!(debug_assertions) {
            println!("{}[{}][{}] = {:?}", stringify!($x), $i, $j, $x[$i][$j]);
        }
    };
    ( $x:expr ) => {
        if cfg!(debug_assertions) {
            println!("{}:{} {} = {:?}", line!(), column!(), stringify!($x), $x);
        }
    };
}

/// Return the smallest power of 2 such that<br>
/// it is greater than or equal to <code>x</code>.
/// # Panics
/// <code>x == 0</code> will cause underflow.
pub fn clp(mut x: usize) -> usize {
    x -= 1;
    x = x | (x >>  1);
    x = x | (x >>  2);
    x = x | (x >>  4);
    x = x | (x >>  8);
    x = x | (x >> 16);
    x = x | (x >> 32);
    x + 1
}

struct RangeUpdateQuery<T, F> where
    T: Copy,
    F: Fn(T, T) -> T
{
    n: usize,
    f: F,
    unit: T,
    a: Vec<Option<T>>,
}

impl<T, F> RangeUpdateQuery<T, F> where
    T: Copy + std::fmt::Debug,
    F: Fn(T, T) -> T
{
    pub fn new(m: usize, f: F, unit: T) -> RangeUpdateQuery<T, F> {
        let n = clp(m);
        Self {
            n: n,
            f: f,
            unit: unit,
            a: vec![Some(unit); 2 * n - 1]
        }
    }

    fn _update(&mut self, update_first: usize, update_last: usize, new_value: T, node: usize, node_first: usize, node_last: usize) {
        //println!("update_first = {}, update_last = {}, node = {}, node_first = {}, node_last = {}",
    //        update_first, update_last, node, node_first, node_last);
        if node_last <= update_first || update_last <= node_first {
         //   println!("nothing to do");
            return;
        } else if update_first <= node_first && node_last <= update_last {
          //  println!("change all elements");
            self.a[node] = Some(new_value);
        } else {
           // println!("split");
            if self.a[node].is_some() {
                self.a[2 * node + 1] = self.a[node];
                self.a[2 * node + 2] = self.a[node];
                self.a[node] = None;
            }
            let node_mid: usize = node_first + (node_last - node_first) / 2;
            self._update(update_first, update_last, new_value, 2 * node + 1, node_first, node_mid);
            self._update(update_first, update_last, new_value, 2 * node + 2, node_mid, node_last);
        }
    }

    pub fn update(&mut self, update_first: usize, update_last: usize, new_value: T) {
        let n = self.n;
        self._update(update_first, update_last, new_value, 0, 0, n);
    }

    fn _query(&self, query_first: usize, query_last: usize, node: usize, node_first: usize, node_last: usize) -> T {
        //println!("query_first = {}, query_last = {}, node = {}, node_first = {}, node_last = {}",
     //       query_first, query_last, node, node_first, node_last);
        if node_last <= query_first || query_last <= node_first {
         //   println!("out of search scope, return unit");
            self.unit
        } else if self.a[node].is_some() {
          //  println!("already calculated, return {:?}", self.a[node].unwrap());
            self.a[node].unwrap()
        } else {
            //println!("new calculation start");
            let node_mid: usize = node_first + (node_last - node_first) / 2;
            let left: T = self._query(query_first, query_last, node * 2 + 1, node_first, node_mid);
            let right: T = self._query(query_first, query_last, node * 2 + 2, node_mid, node_last);
            //println!("new calculation end. return {:?}", (self.f)(left, right));
            (self.f)(left, right)
        }
    }

    pub fn query(&self, first: usize, last: usize) -> T {
        self._query(first, last, 0, 0, self.n)
    }
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin = my::io::InputReader::new(stdin.lock());

    let n: usize = stdin.read();
    let q: usize = stdin.read();
    let mut ruq = RangeUpdateQuery::new(n, |x, y| std::cmp::min(x, y), std::i32::MAX);
    for _ in 0..q {
        let query_type: i32 = stdin.read();
        if query_type == 0 {
            let first: usize = stdin.read();
            let last: usize = stdin.read::<usize>() + 1;
            let x: i32 = stdin.read();
            //println!("update query [{}, {}) <- {}", first, last, x);
            ruq.update(first, last, x);
        } else if query_type == 1 {
            let first: usize = stdin.read();
            let last: usize = stdin.read::<usize>() + 1;
            //println!("search query [{}, {})", first, last);
            println!("{}", ruq.query(first, last));
        }
        //println!("");
    }
}

#[allow(unused_must_use)]
mod my {
    pub mod io {
        use std::io::{BufRead, ErrorKind, Result};
        use std::str::{FromStr, from_utf8};
        use std::fmt::Debug;

        pub fn read_word<R: BufRead>(r: &mut R, buf: &mut Vec<u8>)
                                              -> Result<usize> {
            let mut read = 0;
            loop {
                let (done, used) = {
                    let available = match r.fill_buf() {
                        Ok(n) => n,
                        Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
                        Err(e) => return Err(e)
                    };
                    match available.iter().position(|&x| x == b'\n' || x == b' ') {
                        Some(i) => {
                            buf.extend_from_slice(&available[..i]);
                            (true, i + 1)
                        }
                        None => {
                            buf.extend_from_slice(available);
                            (false, available.len())
                        }
                    }
                };
                r.consume(used);
                read += used;
                if done || used == 0 {
                    return Ok(read);
                }
            }
        }

        pub struct InputReader<R: BufRead> {
            reader: R,
            buf: Vec<u8>,
        }

        impl<R: BufRead> InputReader<R> {
            pub fn new(reader: R) -> InputReader<R> {
                InputReader {
                    reader: reader,
                    buf: Vec::<u8>::new(),
                }
            }

            pub fn read_word(&mut self) {
                read_word(&mut self.reader, &mut self.buf);
            }
            
            pub fn read<T>(&mut self) -> T
                where T: FromStr,
                      T::Err: Debug
            {
                self.buf.clear();
                self.read_word();
                from_utf8(&self.buf).unwrap().trim().parse().unwrap()
            }
        }
    }
}