Cod sursa(job #569170)
#include <fstream>
using namespace std;
const int N=100002;
int v[4*N],n,x,y,val,rasp,nr;
ifstream in("arbint.in");
ofstream out("arbint.out");
inline void nod_update(int &a,int b,int c)
{
a=(b>c ? b:c);
}
inline void ans_update(int x)
{
rasp=(rasp>x ? rasp:x);
}
inline void update(int poz,int st,int dr)
{
if (st==dr)
{
v[poz]=val;
return;
}
int m=(st+dr)>>1;
if (x<=m)
update(poz<<1,st,m);
else
update((poz<<1)+1,m+1,dr);
nod_update(v[poz],v[poz<<1],v[(poz<<1)+1]);
}
inline void query(int poz,int st,int dr)
{
if (st>=x && dr<=y)
{
ans_update(v[poz]);
return;
}
int m=(st+dr)>>1;
if (m>=x)
query(poz<<1,st,m);
if (m<y)
query((poz<<1)+1,m+1,dr);
}
int main()
{
int m;
in>>n>>m;
for (x=1;x<=n;x++)
{
in>>val;
update(1,1,n);
}
for (int i=1;i<=m;i++)
{
in>>x;
if (!x)
{
in>>x>>y;
rasp=0;
query(1,1,n);
out<<rasp<<"\n";
continue;
}
in>>x>>val;
update(1,1,n);
}
return 0;
}