Pagini recente » Cod sursa (job #1481987) | Cod sursa (job #2661538) | Cod sursa (job #2730212) | Cod sursa (job #3147747) | Cod sursa (job #2763763)
#include <bits/stdc++.h>
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
int max1(int a,int b)
{
if (a>b)
{
return a;
}
return b;
}
int n,m,v[100005],maxi[100005],bucket,i,j,maxim,locst,locdr,st,dr,loc,tip,poz,val;
int main()
{
f>>n>>m;
for (i=1;i<=n;i++)
{
f>>v[i];
}
bucket=sqrt(n);
for (i=1;i<=n;i++)
{
loc=(i-1)/bucket;
maxi[loc]=max1(maxi[loc],v[i]);
}
for (i=1;i<=m;i++)
{
f>>tip;
if (tip==0)
{
f>>st>>dr;
locst=(st-1)/bucket;
locdr=(dr-1)/bucket;
maxim=0;
for (j=st;j<=(locst+1)*bucket;j++)
{
maxim=max(maxim,v[j]);
}
for (j=dr;j>=locdr*bucket+1;j--)
{
maxim=max(maxim,v[j]);
}
for (j=locst+1;j<locdr;j++)
{
maxim=max(maxim,maxi[j]);
}
g<<maxim<<'\n';
}
else
{
f>>poz>>val;
v[poz]=val;
maxi[loc]=0;
loc=(poz-1)/bucket;
for (j=bucket*loc+1;j<=bucket*(loc+1);j++)
{
maxi[loc]=max1(maxi[loc],v[j]);
}
}
}
return 0;
}