Pagini recente » Cod sursa (job #454527) | Cod sursa (job #3146002) | Cod sursa (job #2986102) | Cod sursa (job #1125118) | Cod sursa (job #2629133)
#include <fstream>
using namespace std;
ifstream cin("arbint.in");
ofstream cout("arbint.out");
const int lim=1e5;
int tree[2*lim+3];
void update(int x,int y)
{
x+=lim;
tree[x]=y;
for(x/=2;x;x/=2)
tree[x]=max(tree[2*x],tree[2*x+1]);
}
void maxim(int x,int y)
{
x+=lim;
y+=lim;
int ans=tree[x];
while(x<=y)
{
if(x%2==1) ans=max(ans,tree[x++]);
if(y%2==0) ans=max(ans,tree[y--]);
x/=2; y/=2;
}
cout<<ans<<'\n';
}
int main()
{
int n,m,tip,x,y;
cin>>n>>m;
for(int i=1;i<=n;++i)
cin>>tree[lim+i];
for(int i=lim;i;--i)
tree[i]=max(tree[2*i],tree[2*i+1]);
while(m--)
{
cin>>tip>>x>>y;
if(tip) update(x,y);
else maxim(x,y);
}
return 0;
}