Pagini recente » Cod sursa (job #1752310) | Cod sursa (job #3200783) | Cod sursa (job #2917479) | Cod sursa (job #1984141) | Cod sursa (job #3259694)
#include <fstream>
using namespace std;
ifstream cin ("arbint.in");
ofstream cout ("arbint.out");
int v[100001],a,b,maxim,A[400001];
void build (int nod,int st,int dr)
{
if(st==dr)
A[nod]=v[st];
else
{
int m=(st+dr)/2;
build(2*nod,st,m);
build(2*nod+1,m+1,dr);
A[nod]=max(A[2*nod],A[2*nod+1]);
}
}
void update(int nod,int st,int dr)
{
if(st==dr)
A[nod]=b;
else
{
int m=(st+dr)/2;
if(a<=m)
update(2*nod,st,m);
else
update(2*nod+1,m+1,dr);
A[nod]=max(A[2*nod],A[2*nod+1]);
}
}
void q(int nod,int st,int dr)
{
if(a<=st and dr<=b)
maxim=max(maxim,A[nod]);
else
{
int m=(st+dr)/2;
if(a<=m)
q(2*nod,st,m);
if(b>m)
q(2*nod+1,m+1,dr);
}
}
int main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>v[i];
build(1,1,n);
for(int i=1;i<=m;i++)
{
int tip;
cin>>tip>>a>>b;
if(tip==1)
update(1,1,n);
else
maxim=-1,q(1,1,n),cout<<maxim<<"\n";
}
return 0;
}