#include <stdio.h>
class TSegmentTree
{
public:
void Update(int iPos, int iValue);
int Query(int iStart, int iEnd);
TSegmentTree(int iN);
private:
int m_iStart, m_iEnd, iN;
int iValue, iPos;
int m_vTreeHeap[400070];
int iMaxValue;
protected:
void Update (int iNode, int iLeft, int iRight);
void Query (int iNode, int iLeft, int iRight);
};
using namespace std;
//-----------------------------------------------------------------------
int GetMaxim (int a, int b)
{
if (a>b) return a;
return b;
}
//-----------------------------------------------------------------------
void TSegmentTree::Update (int iNode, int iLeft, int iRight)
{
if (iLeft==iRight)
{
this->m_vTreeHeap[iNode]=this->iValue;
return;
}
int iMiddle=(iLeft+iRight)/2;
if (this->iPos<=iMiddle)
this->Update(2*iNode,iLeft,iMiddle);
else
this->Update(2*iNode+1,iMiddle+1,iRight);
this->m_vTreeHeap[iNode]=GetMaxim(this->m_vTreeHeap[2*iNode],this->m_vTreeHeap[2*iNode+1]);
}
//-----------------------------------------------------------------------
void TSegmentTree::Update(int iPos, int iValue)
{
this->iPos=iPos;
this->iValue=iValue;
this->Update(1,1,iN);
}
//-----------------------------------------------------------------------
void TSegmentTree::Query (int iNode, int iLeft, int iRight)
{
if (this->m_iStart<=iLeft && iRight<=this->m_iEnd)
{
if (iMaxValue<this->m_vTreeHeap[iNode])
iMaxValue=this->m_vTreeHeap[iNode];
return;
}
int iMiddle=(iLeft+iRight)/2;
if (this->m_iStart<=iMiddle)
this->Query(2*iNode,iLeft,iMiddle);
if (iMiddle+1<=this->m_iEnd)
this->Query (2*iNode+1, iMiddle+1, iRight);
}
//-----------------------------------------------------------------------
int TSegmentTree::Query(int iStart, int iEnd)
{
iMaxValue=-1;
this->m_iStart=iStart;
this->m_iEnd=iEnd;
this->Query(1,1,iN);
return iMaxValue;
}
//-----------------------------------------------------------------------
TSegmentTree::TSegmentTree(int iN)
{
this->iN=iN;
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
void ReadData(TSegmentTree * objTree)
{
FILE * fIn = fopen("arbint.in","r");
int m,n;
int iValue,iVal1,iVal2;
fscanf (fIn,"%d %d", &n,&m);
objTree = new TSegmentTree(n);
for(int i=1;i<=n;i++)
{
fscanf(fIn,"%d",&iValue);
objTree->Update(i,iValue);
}
FILE * fOut = fopen("arbint.out","w");
for (int i=1;i<=m;i++)
{
fscanf(fIn,"%d %d %d",&iValue,&iVal1,&iVal2);
if (iValue==0)
{
fprintf(fOut,"%d\n",objTree->Query(iVal1,iVal2));
}
else
{
objTree->Update(iVal1,iVal2);
}
}
fclose(fIn);
fclose(fOut);
}
int main()
{
TSegmentTree * objTree;
ReadData(objTree);
return 0;
}