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: Accepted)

import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int q = in.nextInt();
		
		init(n);
		for (int i=0;i<q;i++) {
			if(in.nextInt()==0) {
				// update
				update(in.nextInt(), in.nextInt());
			} else {
				// find
				System.out.println(find(in.nextInt(), in.nextInt()));
			}
		}
	}
	
	static int[] nodes;
	static int size; // up to 2^n

	static void init(int n) { // n:data size
		size=1;
		while (size<n) size*=2;
		nodes = new int[size*2-1];
		for (int i=0;i<nodes.length;i++) {
			nodes[i] = Integer.MAX_VALUE;
		}
	}
	
	static void update(int target, int value) {
		int up = size-1 + target;
		nodes[up] = value;
		if (up==0) return;
		up = (up-1)/2;
		while (true) {
			nodes[up] = Math.min(nodes[up*2+1], nodes[up*2+2]);
			if (up==0) break;
			up = (up-1)/2;
		}
	}
	
	static int find(int s, int t) { // find min in s<=i<=t
		return _find(s, t, 0, 0, size-1);
	}
	static int _find(int s, int t, int node, int node_s, int node_t) {
		if (t<node_s||s>node_t) return Integer.MAX_VALUE;
		if (s<=node_s&&node_t<=t) return nodes[node];
		int cl = _find(s, t, node*2+1, node_s, (node_s+node_t)/2);
		int rl = _find(s, t, node*2+2, (node_s+node_t)/2+1, node_t);
		return Math.min(cl, rl);
	}
}