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 OCaml (judge verdict: Wrong Answer)

open Printf
open Scanf

let () =
  let n, q = scanf "%d %d " (fun a b -> (a, b)) in
  let b = 300 in
  let iv = 2147483647 in
  let ar = Array.make n iv in
  let ubk = Array.make ((n + b - 1) / b) None in
  let mbk = Array.make ((n + b - 1) / b) iv in
  let wb i = match ubk.(i) with
      None -> ()
    | Some v -> let rec iter j =
                  if j = b then ubk.(i) <- None
                  else begin
                      ar.(i*b+j) <- v;
                      iter (j+1)
                    end in
                iter 0;
                mbk.(i) <- v
  in
  let update s t x =
    let rec iter i =
      if i >= t then ()
      else
        if i mod b = 0 && i + b <= t then
          begin
            ubk.(i / b) <- Some x;
            mbk.(i / b) <- x;
            iter (i + b)
          end
        else
          begin
            (match ubk.(i / b) with
               None -> ()
             | Some _ -> wb (i / b));
            ar.(i) <- x;
            mbk.(i / b) <- min mbk.(i / b) x;
            iter (i + 1)
          end
    in iter s
  in
  let find s t =
    let rec iter i m =
      if i >= t then m
      else
        if i mod b = 0 && i + b <= t then
          iter (i + b) (min m mbk.(i / b))
        else
          iter (i + 1) (min m ar.(i))
    in
    iter s iv
  in
  let rec loop c =
    if c = 0 then ()
    else
      begin
        (let com = scanf "%d " (fun u -> u) in
        if com = 0 then
          let s, t, x = scanf "%d %d %d " (fun u v w -> (u, v+1, w)) in
          update s t x
        else
          let s, t = scanf "%d %d " (fun u v -> (u, v+1)) in
          find s t |> printf "%d\n");
        loop (c - 1)
      end
  in
  loop q