Pagini recente » Cod sursa (job #2097705) | Monitorul de evaluare | Cod sursa (job #2885656) | Cod sursa (job #641649) | Cod sursa (job #2026255)
#include <fstream>
#define in "arbint.in"
#define out "arbint.out"
#define N 100003
using namespace std;
ifstream fin(in);
ofstream fout(out);
int heap[2*N],n,m,p,a,b;
int pos,val;
int maxim;
inline void actualizare(int nod,int st,int dr)
{
if(st == pos && dr == pos)
heap[nod] = val;
else
{
int mij = st + (dr-st)/2;
if(pos<=mij) actualizare(nod*2,st,mij);
else actualizare(nod*2+1,mij+1,dr);
heap[nod] = max(heap[nod*2],heap[nod*2+1]);
}
}
inline void DEI(const int &nod,int st,int dr,const int &a,const int &b)
{
if(a<=st && dr<=b)
maxim = max(maxim,heap[nod]);
else
{
int mij = st + (dr-st)/2;
if(a <= mij) DEI(nod*2,st,mij,a,b);
if(b > mij) DEI(nod*2+1,mij+1,dr,a,b);
}
}
int main()
{
fin>>n>>m;
for(int i=1; i<=n; ++i)
{
fin>>val;
pos = i;
actualizare(1,1,n);
}
while(m--)
{
fin>>p>>a>>b;
if(p == 0)
{
maxim = 0;
DEI(1,1,n,a,b);
fout<<maxim<<"\n";
}
else
{
pos = a;
val = b;
actualizare(1,1,n);
}
}
fin.close(); fout.close();
return 0;
}