Problem:
Range Minimum Query (RMQ)

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

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

update(i, x): change ai to x.

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

Input

n q
com0 x0 y0
com1 x1 y1
...
comq−1 xq−1 yq−1

In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).

Output

For each find operation, print the minimum element.

Constraints

1 ≤ n ≤ 100000

1 ≤ q ≤ 100000

If comi is 0, then 0 ≤ xi < n, 0 ≤ yi < 231-1.

If comi is 1, then 0 ≤ xi < n, 0 ≤ yi < n.

Sample Input 1

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

Sample Output 1

1
2

Sample Input 2

1 3
1 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.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush=
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var N = cin.ReadInt;
			var Q = cin.ReadInt;
			var T = new SegmentTree<int>(N, Min, int.MaxValue);
			Func<int, int, int> REPLACE = (i, j) => i;
			for(int j = 0; j<Q; j++) {
				var query = cin.ReadIntArray(3);
				switch(query[0]) {
					case 0:
						T.ImmediateOperate(query[1], query[2], REPLACE);
						break;
					default:
						Console.WriteLine(T.GetValue(query[1], query[2]+1));
						break;
				}
			}
		}
	}
	static class ExtendClass {
		public static void Swap<T>(this T[] A, int x, int y) {
			var tmp = A[x];
			A[x]=A[y];
			A[y]=tmp;
		}
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
		public static IEnumerable<int> Indices<T>(this T[] X) => Enumerable.Range(0, X.Length);
		public static IEnumerable<int> Indices<T>(this T[,] X, int dim)
			=> Enumerable.Range(0, X.GetLength(dim));
		public static string Join<T>(this T[,] X, string separatorD2 = ",", string separatorD1 = "\n")
			=> X.Indices(0).Select(
				i => X.Indices(1).Select(j => X[i, j]).Join(separatorD2)
			).Join(separatorD1);
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator=separator;
			this._stream=stream;
			inputStream=new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count!=0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i<tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i<N; ++i)
				ret[i]=Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i<N; ++i) ret[i]=ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i<N; ++i) ret[i]=ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i<N; ++i) ret[i]=ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek()==-1; }
		}
	}
	class SegmentTree<T> {
		public readonly int rank;
		public T[] Nodes { get; }
		public Func<T, T, T> OPER { get; }
		public T unit { get; }
		private int width { get { return 1<<(rank-1); } }
		private T raise(int c) {
			return (c&1)==0
			? OPER(Nodes[c-1], Nodes[(c-1)+1]) //$c is even
			: OPER(Nodes[(c-1)-1], Nodes[c-1]); //odd
		}
		private int leafIndex(int x) => (1<<(rank-1))+(x-1);
		public SegmentTree(int count, Func<T, T, T> _OPER, T _unit) {
			if(count==0) throw new ArgumentNullException();
			rank=count==1 ? 1 : (int)Log(count-1, 2)+2;
			Nodes=Enumerable.Repeat(_unit, (1<<rank)-1).ToArray();
			OPER=_OPER;
			unit=_unit;
		}
		public void ImmediateUpdate(int x, T value) {
			var r = rank-1;
			var jc = (1<<r)+x;
			Nodes[jc-1]=value;
			for(r--; r>=0; r--) {
				var parentIndex = (jc>>1)-1;
				var oldValue = Nodes[parentIndex];
				Nodes[parentIndex]=raise(jc);
				if(oldValue.Equals(Nodes[parentIndex])) break;
				jc>>=1;
			}
		}
		public void ImmediateOperate<S>(int x, S value, Func<S, T, T> LeftOP) {
			ImmediateUpdate(x, LeftOP(value, Nodes[leafIndex(x)]));
		}
		public T GetValue(int start, int end) => GV(start, end, 1, 0, width);
		private T GV(int start, int end, int count, int focusStart, int focusEnd) {
			if(focusEnd<=start||end<=focusStart) return unit;
			if(start<=focusStart&&focusEnd<=end) return Nodes[count-1];
			var mid = focusStart+(focusEnd-focusStart)/2;
			return OPER(
				GV(start, end, count*2, focusStart, mid),
				GV(start, end, count*2+1, mid, focusEnd)
			);
		}
		public IEnumerable<T> GetLayer(int c) => Nodes.Skip((1<<(c-1))-1).Take(1<<(c-1));
		public IEnumerable<T> GetLeaves() => Nodes.Skip((1<<(rank-1))-1).Take(1<<(rank-1));

	}
}