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: Wrong Answer)

using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		long n = long.Parse(input[0]);
		long q = long.Parse(input[1]);
    long[] nums = new long[400*400];
    long[] numSetsMin = new long[400];//400*400に分割
    long minMemo = long.MaxValue;

    for(long i = 0; i < 400*400; i++)
    {
      nums[i] = 2147483647;//初期化
    }
    for(long i = 0; i < 400; i++)
    {
      numSetsMin[i] = 2147483647;//初期化
    } 

    for(long question = 0; question < q; question++)
    {
      string[] inputq = Console.ReadLine().Split(' ');
      long howNum = long.Parse(inputq[0]);
      long leftNum = long.Parse(inputq[1]);
      long rightNum = long.Parse(inputq[2]);
      if(howNum == 0)//書き換え
      {
        nums[leftNum] = rightNum;
        long numPosition = WherePosition(leftNum);//どの分類に属するか
        numSetsMin[numPosition] = Math.Min(numSetsMin[numPosition], rightNum);
      }
      if(howNum == 1)//最小値を求める
      {
        minMemo = long.MaxValue;
        long leftPosition = WherePosition(leftNum);
        long rightPosition = WherePosition(rightNum);

        if(leftPosition == rightPosition)
        {
          for(long i = leftNum; i <= rightNum; i++)//左右が同じ分類のとき
          {
            minMemo = Math.Min(minMemo, nums[i]);
          }
        }else
        {
          for(long i = leftNum; i < 400*leftPosition; i++)//左区間内（左端より右だけ見る）
          {
            minMemo = Math.Min(minMemo, nums[i]);
          }
          for(long i = 400*rightPosition; i <= rightNum; i++)//右区間内
          {
            minMemo = Math.Min(minMemo, nums[i]);
          }
          for(long i = leftPosition+1; i < rightPosition; i++)//見ていない区間内
          {
            minMemo = Math.Min(minMemo, numSetsMin[i]);
          }
        }
        Console.WriteLine(minMemo);
      }
    }
	}

  static long WherePosition(long num)//左から何番目の分類に属するか
  {
    return num / 400;
  }
  
}