Pagini recente » Cod sursa (job #983958) | Cod sursa (job #3140731) | Cod sursa (job #100816) | Cod sursa (job #133508) | Cod sursa (job #2572472)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
int n,m,v[100005],maxx,x, y;
pair<pair<int,int>, int> arb[500005];
void construct(int nod, int st, int dr)
{
int mij;
arb[nod].first.first=st;
arb[nod].first.second=dr;
if(st!=dr)
{
mij=(st+dr)/2;
construct(2*nod,st,mij);
construct(2*nod+1,mij+1,dr);
arb[nod].second=max(arb[2*nod].second,arb[2*nod+1].second);
}
else
arb[nod].second=v[st];
}
void maxim(int nod)
{
int mij,st,dr,val;
st=arb[nod].first.first;
dr=arb[nod].first.second;
if(x<=st and dr<=y)
{
val=arb[nod].second;
maxx=max(val,maxx);
}
else
{
mij=(st+dr)/2;
if(x<=mij)
maxim(2*nod);
if(y>mij)
maxim(2*nod+1);
}
}
void inloc(int nod)
{
int mij,st,dr;
st=arb[nod].first.first;
dr=arb[nod].first.second;
if(st==dr and st==x)
arb[nod].second=y;
else
{
mij=(st+dr)/2;
if(x<=mij)
{
inloc(2*nod);
}
else
{
inloc(2*nod+1);
}
arb[nod].second=max(arb[2*nod+1].second,arb[2*nod].second);
}
}
int main()
{
int i,j,p;
fin>>n>>m;
for(i=1;i<=n;i++)
fin>>v[i];
construct(1,1,n);
for(i=1;i<=m;i++)
{
fin>>p>>x>>y;
if(p==0)
{
maxx=0;
maxim(1);
fout<<maxx<<endl;
}
else
inloc(1);
}
fin.close();
fout.close();
return 0;
}