Pagini recente » Cod sursa (job #1426492) | Cod sursa (job #951477) | Cod sursa (job #149341) | Cod sursa (job #621321) | Cod sursa (job #1081316)
#include <fstream>
using namespace std;
int n,m,ai[262144],p2=1,lim;
int Build(int nod)
{
int l=nod<<1,r=(nod<<1)+1;
if(r<lim)
ai[nod]=max(Build(l),Build(r));
else if(l<lim)
ai[nod]=Build(l);
return ai[nod];
}
int Max(int a,int b)
{
int nod=1,x=1,y=p2,m;
while((x<a)||(y>b))
{
m=(x+y)>>1;
if(m<a)
{
(nod<<=1)++;
x=m+1;
}
else
{
nod<<=1;
y=m;
}
}
if(y==b)
return ai[nod];
else
return max(ai[nod],Max(y+1,b));
}
void Update(int nod)
{
int p=nod>>1;
if(nod>1)
{
ai[p]=max(ai[nod],ai[nod&1?nod-1:nod+1]);
Update(p);
}
}
ifstream fin("arbint.in");
ofstream fout("arbint.out");
int main()
{
int o,a,b;
fin>>n>>m;
while(p2<n)
p2<<=1;
lim=p2+n;
for(a=p2;a<lim;a++)
fin>>ai[a];
Build(1);
while(m--)
{
fin>>o>>a>>b;
if(o)
{
a+=p2-1;
ai[a]=b;
Update(a);
}
else
fout<<Max(a,b)<<"\n";
}
return 0;
}