Pagini recente » Cod sursa (job #2872840) | Cod sursa (job #2933963) | Cod sursa (job #1778145) | Cod sursa (job #1076239) | Cod sursa (job #2758748)
#include <bits/stdc++.h>
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
const int N=1<<18;
int n,m,a[N],p,c,x,y;
int maxim(int nod, int st, int dr)
{
if(x<=st && dr<=y)
return a[nod];
if(x>dr || st>y)
return 0;
int mi=(st+dr)/2;
return max(maxim(2*nod,st,mi),maxim(2*nod+1,mi+1,dr));
}
int main()
{
f>>n>>m;
p=1;
while(p<n)
p*=2;
for(int i=1;i<=n;i++)
f>>a[p-1+i];
for(int i=p-1;i>=1;i--)
a[i]=max(a[2*i],a[2*i+1]);
for(;m;m--)
{
f>>c>>x>>y;
if(c==1)
{
x=x+p-1;
a[x]=y;
x/=2;
while(x>0)
{
a[x]=max(a[2*x],a[2*x+1]);
x/=2;
}
}
else
g<<maxim(1,1,p)<<'\n';
}
return 0;
}