Pagini recente » Cod sursa (job #1191844) | Cod sursa (job #2152644) | Cod sursa (job #298370) | Cod sursa (job #978036) | Cod sursa (job #2842976)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
using namespace std;
ifstream fin ("arbint.in");
ofstream fout ("arbint.out");
int n,i,j,v[100005],valmax[1005],cap[1005],howmany,nrgr,m,tip,x,y;
int unde[100005];
void newmax(int poz)
{
int rez=0;
for(int i=cap[poz];i<=cap[poz+1]-1;i++) rez=max(rez,v[i]);
valmax[poz]=rez;
}
int calc(int st, int dr)
{
int rez=0;
int first=unde[st];
int last=unde[dr];
if(first==last || first+1==last)
{
for(int i=st;i<=dr;i++) rez=max(rez,v[i]);
return rez;
}
else
{
for(int i=st;i<=cap[first+1]-1;i++) rez=max(rez,v[i]);
for(int i=dr;i>=cap[last];i--) rez=max(rez,v[i]);
for(int i=first+1;i<=last-1;i++) rez=max(rez,valmax[i]);
}
return rez;
}
int main()
{
fin>>n>>m;
howmany=sqrt(n);
j=1;nrgr=1;
for(i=1;i<=n;i++)
{
fin>>v[i];
if(cap[nrgr]==0) cap[nrgr]=i;
valmax[nrgr]=max(valmax[nrgr],v[i]);
unde[i]=nrgr;
j++;
if(j>howmany)
{
j=1;
nrgr++;
}
}
for(i=1;i<=m;i++)
{
fin>>tip>>x>>y;
if(tip==0)
{
fout<<calc(x,y)<<'\n';
}
else
{
v[x]=y;
int where=unde[x];
newmax(where);
}
}
return 0;
}