Pagini recente » Cod sursa (job #2177940) | Cod sursa (job #1587619) | Cod sursa (job #2065825) | Cod sursa (job #2775614) | Cod sursa (job #2854374)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
int const N=(int)1e5+5,V=2*N+69;
int f[V],n,v[N],inc;
void build(int s,int d,int pz)
{
if(s==d)
{
if(pz>inc+n)
f[pz]=-1;
else
f[pz]=v[s];
return;
}
int m=(s+d)/2;
build(s,m,pz*2);
build(m+1,d,pz*2+1);
f[pz]=max(f[pz*2],f[pz*2+1]);
}
int mx(int x,int y,int s,int d,int pz)
{
int m=(s+d)/2;
if(d<x || s>y)
return 0;
if(x<=s && y>=d)
return f[pz];
return max(mx(x,y,s,m,pz*2),mx(x,y,m+1,d,pz*2+1));
}
void upd(int pz)
{
if(!pz)
return;
/// par +1 impar -1 0 1 1 -1
f[pz/2]=max(f[pz],f[pz+1-(pz%2)*2]);
upd(pz/2);
}
void afs()
{
for(int i=1;i<=(inc<<1)+1;i++)
cout<<f[i]<<' ';
cout<<'\n';
}
int main()
{
int q,a,x,y;
fin>>n>>q;
for(int i=1;i<=n;i++)
fin>>v[i];
for(inc=1;inc<n;inc=(inc<<1));
inc--;
///cout<<inc<<'\n';
build(1,inc+1,1);
while(q--)
{
fin>>a>>x>>y;
///afs();
if(a==0)
fout<<mx(x,y,1,inc+1,1)<<'\n';
else
{f[inc+x]=y;upd(inc+x);}
}
}