Pagini recente » Cod sursa (job #2097400) | Cod sursa (job #1119948) | Cod sursa (job #3352108) | Cod sursa (job #3352117) | Cod sursa (job #3312878)
#include <fstream>
#include <math.h>
using namespace std;
ifstream cin("arbint.in");
ofstream cout("arbint.out");
int v[262200];
int n, m, t, a, b, pt=1, tot;
inline void update(int poz, int val)
{
poz=tot+poz-1;
v[poz]=val;
poz/=2;
while(poz>0)
{
v[poz]=max(v[2*poz], v[2*poz+1]);
poz/=2;
}
}
int query(int ind, int st, int dr, int qst, int qdr)
{
if(qst<=st && dr<=qdr)
{
return v[ind];
}
else
{
int mij = (st+dr)/2, mx=0;
if(qst<=mij)
{
mx=max(mx, query(2*ind, st, mij, qst, qdr));
}
if(mij<qdr)
{
mx=max(mx, query(2*ind+1, mij+1, dr, qst, qdr));
}
return mx;
}
}
int main()
{
cin>>n>>m;
tot=log2(n)+1;
tot= (1<<tot);
for(int i=tot; i<tot+n; i++)
{
cin>>v[i];
}
for(int i=tot-1; i>=1; i--)
{
v[i]=max(v[i*2], v[2*i+1]);
}
for(int i=0; i<m; i++)
{
cin>>t>>a>>b;
if(t==0)
{
cout<<query(1, 1, tot, a, b)<<'\n';
}
else
{
update(a, b);
}
}
return 0;
}