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 Go (judge verdict: Accepted)

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	q := getNextInt(scanner)
	seg := newSegment(n)
	seg.update(0, n, math.MaxInt32, seg.min)
	for i := 0; i < q; i++ {
		o := getNextInt(scanner)
		s := getNextInt(scanner)
		t := getNextInt(scanner) + 1
		switch o {
		case 0:
			x := getNextInt(scanner)
			seg.update(s, t, x, seg.min)
		case 1:
			ans := seg.query(s, t, math.MaxInt32, seg.min)
			fmt.Fprintln(writer, ans)
		}
	}
}

type vertex struct {
	v int
	p bool
}
type segment [][]vertex

func newSegment(n int) segment {
	seg := make(segment, 0)
	for n > 1 {
		seg = append(seg, make([]vertex, n))
		n = (n + 1) >> 1
	}
	seg = append(seg, make([]vertex, 1))
	return seg
}
func (seg segment) up(h, i int, f func(x, y int) int) {
	for h = h + 1; h < len(seg); h++ {
		i >>= 1
		if i<<1+1 < len(seg[h-1]) {
			seg[h][i].v = f(seg[h-1][i<<1].v, seg[h-1][i<<1+1].v)
		} else {
			seg[h][i].v = seg[h-1][i<<1].v
		}
	}
}
func (seg segment) propagate(h, i int) {
	if h >= len(seg) {
		return
	}
	seg.propagate(h+1, i>>1)
	if seg[h][i].p == false {
		return
	}
	seg[h][i].p = false
	seg[h-1][i<<1].v = seg[h][i].v
	seg[h-1][i<<1].p = true
	if i<<1+1 >= len(seg[h-1]) {
		return
	}
	seg[h-1][i<<1+1].v = seg[h][i].v
	seg[h-1][i<<1+1].p = true
}
func (seg segment) update(l, r int, v int, f func(x, y int) int) {
	for h := 0; h < len(seg) && l < r; h++ {
		if l&1 == 1 {
			seg.propagate(h+1, l>>1)
			seg[h][l].v = v
			seg[h][l].p = true
			seg.up(h, l, f)
			l++
		}
		l >>= 1
		if r&1 == 1 {
			seg.propagate(h+1, (r-1)>>1)
			seg[h][r-1].v = v
			seg[h][r-1].p = true
			seg.up(h, r-1, f)
		}
		r >>= 1
	}
}
func (seg segment) query(l, r int, s int, f func(x, y int) int) int {
	for h := 0; h < len(seg) && l < r; h++ {
		if l&1 == 1 {
			seg.propagate(h+1, l>>1)
			s = f(s, seg[h][l].v)
			l++
		}
		l >>= 1
		if r&1 == 1 {
			seg.propagate(h+1, (r-1)>>1)
			s = f(s, seg[h][r-1].v)
		}
		r >>= 1
	}
	return s
}
func (seg segment) add(x, y int) int {
	return x + y
}
func (seg segment) min(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func (seg segment) max(x, y int) int {
	return -seg.min(-x, -y)
}