Pagini recente » Cod sursa (job #1088646) | Cod sursa (job #541383) | Cod sursa (job #2514585) | Cod sursa (job #2905691) | Cod sursa (job #2942739)
#include <fstream>
#include <cmath>
using namespace std;
int bloc[1005],v[1000005];
int main()
{
ifstream cin("arbint.in");
ofstream cout("arbint.out");
int n,q,cer,a,b,val,cnt=0;
cin>>n>>q;
val=sqrt(n);
for(int i=0;i<n;i++)
{
cin>>v[i];
bloc[i/val]=max(bloc[i/val],v[i]);
}
for(int Q=1;Q<=q;Q++)
{
cin>>cer>>a>>b;
if(cer==0)
{
a--;
b--;
int poz1=a/val,poz2=b/val,maxx=0;
for(int i=poz1+1;i<poz2;i++)
maxx=max(maxx,bloc[i]);
if(a%val!=0)
{
int np=max(0,(a/val)*val+val-1);
for(int j=np;j>=a;j--)
maxx=max(maxx,v[j]);
}
else
maxx=max(maxx,bloc[poz1]);
if((b-1)%val!=0)
{
int np=min((b/val)*val,n);
for(int j=np;j<=b;j++)
maxx=max(maxx,v[j]);
}
else
maxx=max(maxx,poz2);
cout<<maxx<<'\n';
}
else
{
a--;
v[a]=b;
bloc[a/val]=0;
for(int j=a/val*val;j<a/val*val+val;j++)
bloc[a/val]=max(bloc[a/val],v[j]);
}
}
return 0;
}