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 JAVA (judge verdict: Time Limit Exceeded)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import java.util.Arrays;

public class Main {
	/*
	  TLE?????§????????¨. update???O(n)??\???????????????????¢?????????????.
	  ???????????§??? AC ???????????§, Verify?????????????????£?????????.
	*/
		
	public static class RMQ {
		long[][] sparse_table; // query??? O(1)???????????????, k ????????¢????????????.

		public RMQ(long[] array){ // O(n log n)
			final int depth = Integer.numberOfTrailingZeros(Integer.highestOneBit(array.length));
			sparse_table = new long[depth + 1][]; sparse_table[0] = new long[array.length];
			System.arraycopy(array, 0, sparse_table[0], 0, array.length);

			for(int k = 1; k < sparse_table.length; k++){
				sparse_table[k] = new long[array.length - (1 << k) + 1];
				for(int i = 0; i + (1 << k) <= array.length; i++) { // [i, i + (1 << k))
					// [i, i + (1 << k) -> [i, i + (1 << k) / 2), [i + (1 << k) / 2, i << (k - 1))
					sparse_table[k][i] =
							Math.min(sparse_table[k-1][i], sparse_table[k-1][i + (1 << (k - 1))]);
				}
			}
		}

		public void update(int index, long v){ // index: 0-index
			//update O(n log n) ??§???????????????. SegTree??§?????????.
			sparse_table[0][index] = v;
			for(int k = 1; k < sparse_table.length; k++){
				final int begin = Math.max(0, index - (1 << k) + 1);
				final int end = Math.min(sparse_table[k].length, index + (1 << k));
				// ?????§??§ index + [-(1 << k) + 1, (1 << k)) ??????????????´??°?????????????????????
				for(int i = begin; i < end; i++){
					sparse_table[k][i] =
							Math.min(sparse_table[k - 1][i], sparse_table[k-1][i + (1 << (k - 1))]);
				}
			}
		}

		public long query(int l, int r){ // [l, r) O(log log n)
			final int k = Integer.numberOfTrailingZeros(Integer.highestOneBit(r - l));
			// k -> ???????????????????????????????????§???2?????????
			// left -> [i, i + (1 << k)), right -> [r - (1 << k)] (?????????????????§?±0)
			return Math.min(sparse_table[k][l], sparse_table[k][r - (1 << k)]);
		}
	}
		
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		final int q = sc.nextInt();
		
		long[] array = new long[n];
		Arrays.fill(array, Integer.MAX_VALUE);
		
		RMQ rmq = new RMQ(array);
		for(int tt = 0; tt < q; tt++){
			final int op = sc.nextInt();
			final int x  = sc.nextInt();
			final int y  = sc.nextInt();

			if(op == 0){
				rmq.update(x, y);
			}else{
				System.out.println(rmq.query(x, y + 1));
			}
		}
	}
	
	public static class Scanner {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() {
			try {
				while (!hasNext()) {tok = new StringTokenizer(br.readLine());}
			} catch(IOException e){ /* ignore */ }
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() {
			getLine(); return tok.nextToken();
		}

		public int nextInt(){
			return Integer.parseInt(next());
		}
		// ??????nextXXX???XXX.parseXXX()????????????????????£?????????????????§?????\

		public void close() {
			try{ br.close(); } catch (IOException e){ /*ignore*/ }
		}
	}
}