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

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var avl=new Avl2(false);
		var s=sc.Ia;
		avl.Ud(0,s[0],int.MaxValue);
		StringBuilder sb=new StringBuilder();
		for(int i = 0;i<s[1];i++) {
			var e=sc.Ia;
			if(e[0]==0){avl.Ud(e[1],e[2],e[3]);}
			else{sb.Append(avl.Get(e[1],e[2])+"\n");}
		}
		Console.Write(sb);
	}
}
public class Avl2{
	public class Nd{
		public int h=1,c=1;
		public int nl,nr;
		public long d,dd=0;
		public Nd l,r;
		public bool lf,bd;
		public Nd(int nl,int nr,long d,Nd du){this.nl=nl;this.nr=nr;this.d=d;l=du;r=du;lf=true;}
		public Nd(int nl,int nr,Nd l,Nd r){
			this.nl=nl;this.nr=nr;this.l=l;this.r=r;
			compare(this);
			h=Max(l.h,r.h)+1;
			lf=false;
		}
	}
	public Nd root,du;
	public int cnt=0;
	private static Action<Nd> compare;
	public Avl2(bool bo){
		if(bo){compare=CoMax;}
		else{compare=CoMin;}
		du=new Nd(int.MinValue,int.MaxValue,bo?int.MinValue:int.MaxValue,du);
		du.h=0;du.c=0;
		root=du;
	}
	private void CoMax(Nd nd){
		Fdd(nd.l);Fdd(nd.r);
		if(nd.l.d>nd.r.d){nd.d=nd.l.d;}
		else{nd.d=nd.r.d;}
	}
	private void CoMin(Nd nd){
		Fdd(nd.l);Fdd(nd.r);
		if(nd.l.d<nd.r.d){nd.d=nd.l.d;}
		else{nd.d=nd.r.d;}
	}
	public void Ud(int a,int b,long d){
		if(a>b){a^=b;b^=a;a^=b;}
		if(root!=du){
			root=Fu(root,a,b,d);
			if(Abs(root.l.h-root.r.h)>1){root=Rotate(root);}
		}
		else{root=new Nd(a,b,d,du);}
	}
	private Nd Fu(Nd t,int nl,int nr,long d){
		Fdd(t);
		if(!t.lf){
			if(t.nl==nl&&t.nr==nr){
				t.d=d;
				t.l.dd=d;
				t.r.dd=d;
				t.l.bd=t.r.bd=true;
				t.bd=false;
				return t;
			}
			if(t.l.nr>=nl){t.l=Fu(t.l,nl,Min(t.l.nr,nr),d);}
			if(t.l.nr<nr){t.r=Fu(t.r,Max(t.l.nr+1,nl),nr,d);}
			if(Abs(t.l.l.h-t.l.r.h)>1){t.l=Rotate(t.l);}
			if(Abs(t.r.l.h-t.r.r.h)>1){t.r=Rotate(t.r);}
			compare(t);
			t.nl=t.l.nl;
			t.nr=t.r.nr;
			t.h=Max(t.l.h,t.r.h)+1;
		}
		else{
			if(t.nr<nl){return new Nd(t.nl,nr,t,new Nd(nl,nr,d,du));}
			else if(t.nl>nr){return new Nd(nl,t.nr,new Nd(nl,nr,d,du),t);}
			else if(t.nl<nl){
				if(t.nr<nr){
					Nd e=new Nd(t.nl,nr,t,new Nd(nl,nr,new Nd(nl,t.nr,d,du),new Nd(t.nr+1,nr,d,du)));
					t.nr=nl-1;
					return e;
				}
				else if(t.nr>nr){
					Nd e=new Nd(t.nl,t.nr,t,new Nd(nl,t.nr,new Nd(nl,nr,d,du),new Nd(nr+1,t.nr,t.d,du)));
					t.nr=nl-1;
					return e;
				}
				else{
					t.nr=nl-1;
					return new Nd(t.nl,nr,t,new Nd(nl,nr,d,du));
				}
			}
			else if(t.nl>nl){
				if(t.nr<nr){
					Nd e=new Nd(nl,nr,new Nd(nl,t.nl-1,d,du),new Nd(t.nl,nr,t,new Nd(t.nr+1,nr,d,du)));
					t.d=d;
					return e;
				}
				else if(t.nr>nr){
					Nd e=new Nd(nl,t.nr,new Nd(nl,t.nl-1,d,du),new Nd(t.nl,t.nr,new Nd(t.nl,nr,d,du),t));
					t.nl=nr+1;
					return e;
				}
				else{
					t.d=d;
					return new Nd(nl,nr,new Nd(nl,t.nl-1,d,du),t);
				}
			}
			else{
				if(t.nr<nr){
					t.d=d;
					return new Nd(nl,nr,t,new Nd(t.nr+1,nr,d,du));
				}
				else if(t.nr>nr){
					t.nl=nr+1;
					return new Nd(nl,t.nr,new Nd(nl,nr,d,du),t);
				}
				else{
					t.d=d;
					return t;
				}
			}
		}
		return t;
	}
	public long Get(int a,int b){
		return Fdg(root,a,b);
	}
	private long Fdg(Nd t,int nl,int nr){
		Fdd(t);
		if(t.lf){return t.d;}
		if(nl<=t.nl&&nr>=t.nr){return t.d;}
		long d=long.MaxValue;
		if(t.l.nr>=nl){d=Fdg(t.l,nl,nr);}
		if(t.r.nl<=nr){d=Min(d,Fdg(t.r,nl,nr));}
		return d;
	}
	private void Fdd(Nd t){
		if(t.bd){
			t.d=t.dd;
			t.l.dd=t.r.dd=t.dd;
			t.l.bd=t.r.bd=true;
			t.bd=false;
		}
	}
	private Nd Rotate(Nd t){
		Nd nd=du;
		Fdd(t);
		if(t.l.h>t.r.h){
			Fdd(t.l);
			if(t.l.l.h>t.l.r.h){
				nd=t.l;t.l=t.l.r;nd.r=t;
				Ft(t);
			}
			else{
				Fdd(t.l.r);
				nd=t.l.r;
				t.l.r=nd.l;nd.l=t.l;
				Ft(t.l);
				t.l=nd.r;nd.r=t;
				Ft(t);
			}
		}
		else{
			Fdd(t.r);
			if(t.r.l.h>t.r.r.h){
				Fdd(t.r.l);
				nd=t.r.l;
				t.r.l=nd.r;nd.r=t.r;
				Ft(t.r);
				t.r=nd.l;nd.l=t;
				Ft(t);
			}
			else{
				nd=t.r;t.r=t.r.l;nd.l=t;
				Ft(t);
			}
		}
		Ft(nd);
		return nd;
	}
	private void Ft(Nd t){
		if(!t.lf){
			t.h=Max(t.l.h,t.r.h)+1;
			t.c=t.l.c+t.r.c;
			compare(t);
			t.nl=t.l.nl;
			t.nr=t.r.nr;
		}
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}