using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("8 4");
WillReturn.Add("1 3 16");
WillReturn.Add("2 4 7");
WillReturn.Add("1 5 13");
WillReturn.Add("2 4 7");
//0
//13
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
int[] wkArr = { };
Action<string> SplitAct = pStr =>
wkArr = pStr.Split(' ').Select(pX => int.Parse(pX)).ToArray();
SplitAct(InputList[0]);
int N = wkArr[0];
var InsSegmentTree = new SegmentTree(N + 1);
for (int I = 0; I <= N; I++) {
InsSegmentTree.Update(I, 0);
}
foreach (string EachStr in InputList.Skip(1)) {
SplitAct(EachStr);
int T = wkArr[0];
if (T == 1) {
int Pos = wkArr[1];
int X = wkArr[2];
InsSegmentTree.Update(Pos, X);
}
if (T == 2) {
int L = wkArr[1];
int R = wkArr[2];
Console.WriteLine(InsSegmentTree.Query(L, R - 1, 0));
}
}
}
}
#region SegmentTree
// SegmentTreeクラス (RMaxQ and 1点更新)
internal class SegmentTree
{
private int[] mTreeNodeArr;
private int UB; // 木のノードの配列のUB
private int mLeafCnt; // 葉ノードの数
// ノードの添字を引数とし、範囲の開始添字と終了添字を持つ配列
private struct RangeInfoDef
{
internal int StaInd;
internal int EndInd;
}
private RangeInfoDef[] mRangeInfo;
// コンストラクタ
internal SegmentTree(int pLeafCnt)
{
// 簡単のため、葉ノード数を2のべき乗に
int ArrLength = 0;
for (int I = 1; I < int.MaxValue; I *= 2) {
ArrLength += I;
mLeafCnt = I;
if (pLeafCnt < mLeafCnt) break;
}
// すべての値をint.MinValueに
UB = ArrLength - 1;
mTreeNodeArr = new int[UB + 1];
for (int I = 0; I <= UB; I++) {
mTreeNodeArr[I] = int.MinValue;
}
// ノードの添字を引数とし、範囲の開始添字と終了添字を持つ配列の作成
mRangeInfo = new RangeInfoDef[UB + 1];
for (int I = 0; I <= UB; I++) {
if (I == 0) {
RangeInfoDef WillSet1;
WillSet1.StaInd = 0;
WillSet1.EndInd = mLeafCnt - 1;
mRangeInfo[I] = WillSet1;
continue;
}
int ParentNode = DeriveParentNode(I);
RangeInfoDef ParentRangeInfo = mRangeInfo[ParentNode];
RangeInfoDef WillSet2;
int Mid = (ParentRangeInfo.StaInd + ParentRangeInfo.EndInd) / 2;
if (I % 2 == 1) { // 奇数ノードの場合
WillSet2.StaInd = ParentRangeInfo.StaInd;
WillSet2.EndInd = Mid;
}
else { // 偶数ノードの場合
WillSet2.StaInd = Mid + 1;
WillSet2.EndInd = ParentRangeInfo.EndInd;
}
mRangeInfo[I] = WillSet2;
}
}
// 親ノードの添字を取得
private int DeriveParentNode(int pTarget)
{
return (pTarget - 1) / 2;
}
// 子ノードの添字(小さいほう)を取得
private int DeriveChildNode(int pTarget)
{
return pTarget * 2 + 1;
}
// 葉ノードの配列の添字を木の添字に変換して返す
private int DeriveTreeNode(int pLeafArrInd)
{
int BaseInd = UB - mLeafCnt + 1;
return BaseInd + pLeafArrInd;
}
// 葉ノードの配列のK番目の値をNewValに変更
internal void Update(int pK, int pNewVal)
{
int CurrNode = DeriveTreeNode(pK);
mTreeNodeArr[CurrNode] = pNewVal;
// 登りながら更新
while (CurrNode > 0) {
CurrNode = DeriveParentNode(CurrNode);
int ChildNode1 = DeriveChildNode(CurrNode);
int ChildNode2 = ChildNode1 + 1;
mTreeNodeArr[CurrNode] =
Math.Max(mTreeNodeArr[ChildNode1], mTreeNodeArr[ChildNode2]);
}
}
// 開始添字と終了添字とカレントノードを引数として、最大値を返す
internal int Query(int pSearchStaInd, int pSearchEndInd, int pCurrNode)
{
int CurrNodeStaInd = mRangeInfo[pCurrNode].StaInd;
int CurrNodeEndInd = mRangeInfo[pCurrNode].EndInd;
// OverLapしてなければ、int.MinValue
if (CurrNodeEndInd < pSearchStaInd || pSearchEndInd < CurrNodeStaInd)
return int.MinValue;
// 完全に含んでいれば、このノードの値
if (pSearchStaInd <= CurrNodeStaInd && CurrNodeEndInd <= pSearchEndInd)
return mTreeNodeArr[pCurrNode];
// そうでなければ、2つの子の最大値
int ChildNode1 = DeriveChildNode(pCurrNode);
int ChildNode2 = ChildNode1 + 1;
int ChildVal1 = Query(pSearchStaInd, pSearchEndInd, ChildNode1);
int ChildVal2 = Query(pSearchStaInd, pSearchEndInd, ChildNode2);
return Math.Max(ChildVal1, ChildVal2);
}
}
#endregion