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)

use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());

    let n = scan.read::<usize>();
    let q = scan.read::<usize>();
    let v = vec![(1i64<<31) - 1; n];
    let mut segtree = SegRangeUpdate::new(v, (1i64<<31)-1, std::cmp::min);
    for _ in 0..q {
        let com = scan.read::<i32>();
        if com == 0 {
            let s = scan.read::<usize>();
            let t = scan.read::<usize>();
            let x = scan.read::<i64>();
            segtree.set(s..t+1, x);
        } else {
            let s = scan.read::<usize>();
            let t = scan.read::<usize>();
            println!("{}", segtree.get(s..t+1));
        }
    }
}

use std::ops::Range;

fn contains(p: &Range<usize>, q: &Range<usize>) -> bool {
    p.start <= q.start && q.end <= p.end
}

fn separates(p: &Range<usize>, q: &Range<usize>) -> bool {
    p.end <= q.start || q.end <= p.start
}

fn size(p: &Range<usize>) -> usize {
    p.end - p.start
}

struct SegRangeUpdate<'a> {
    node: Vec<i64>,
    lazy: Vec<i64>,
    has_lazy: Vec<bool>,
    op: Box<Fn(i64, i64) -> i64 + 'a>,
    zero: i64,
    n: usize,
}

impl <'a> SegRangeUpdate<'a> {
    fn new<B>(v: Vec<i64>, zero: i64, op: B) -> SegRangeUpdate<'a> where B: Fn(i64, i64) -> i64 + 'a {
        let size = v.len();
        let mut n = 1usize;
        while n < size {n *= 2}
        let mut node = vec![zero; 2*n-1];
        let lazy = vec![0; 2*n-1];
        let has_lazy = vec![false; 2*n-1];
        for i in 0..size {node[i+n-1] = v[i]}
        for i in (0..n - 1).rev() {node[i] = op(node[i*2+1], node[i*2+2])}
        SegRangeUpdate {node: node, lazy: lazy, has_lazy: has_lazy, op: Box::new(op), zero, n: n}
    }

    fn eval(&mut self, k: usize, range: Range<usize>) {
        if self.has_lazy[k] {
            self.node[k] = self.lazy[k];
            if size(&range) > 1 {
                self.lazy[2*k+1] = self.lazy[k];
                self.lazy[2*k+2] = self.lazy[k];
                self.has_lazy[2*k+1] = true;
                self.has_lazy[2*k+2] = true;
            }
            self.has_lazy[k] = false;
        }
    }

    fn set(&mut self, query: Range<usize>, x: i64) {
        let n = self.n;
        self.setrec(query, x, 0,  0..n )
    }

    fn setrec(&mut self, query: Range<usize>, x: i64, k: usize, range: Range<usize>) {
        self.eval(k, range.clone());
        if separates(&query, &range) {return}
        if contains(&query, &range) {
            self.lazy[k] = x;
            self.has_lazy[k] = true;
            self.eval(k, range.clone());
        } else {
            self.setrec(query.clone(), x, 2*k+1, range.start..(range.start+range.end)/2);
            self.setrec(query.clone(), x, 2*k+2, (range.start+range.end)/2..range.end);
            self.node[k] = (self.op)(self.node[2*k+1], self.node[2*k+2]);
        }
    }

    fn get(&mut self, query: Range<usize>) -> i64 {
        let n = self.n;
        self.getrec(query, 0, 0..n)
    }

    fn getrec(&mut self, query: Range<usize>, k: usize, range: Range<usize>) -> i64 {
        if separates(&query, &range) {return self.zero}
        self.eval(k, range.clone());
        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 uz(i: i32) -> usize { i as usize }

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<T: FromStr>(&mut self) -> Option<T> {
        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::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: i32) -> Vec<T> {
        let mut ret = vec![];
        for _ in 0..n { ret.push(self.read::<T>()) }
        ret
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion