Pagini recente » Cod sursa (job #611053) | Cod sursa (job #2400080) | Cod sursa (job #1147844) | Cod sursa (job #2350831) | Cod sursa (job #2025461)
#include <fstream>
#define max(a,b) (a > b ? a:b)
#define in "arbint.in"
#define out "arbint.out"
#define NOD 200003
using namespace std;
ifstream fin(in);
ofstream fout(out);
int n,m,p,a,b;
int pos,val;
int heap[NOD];
int Max;
inline void actualizare(int nod,int st,int dr)
{
if(pos == st && pos == dr)
{
heap[nod] = val;
}
else
{
int mij = (st+dr)/2;
if(pos >= st && pos <= mij) actualizare(2*nod,st,mij);
if(pos > mij && pos <= dr) actualizare(2*nod+1,mij+1,dr);
heap[nod] = max(heap[2*nod],heap[2*nod+1]);
}
}
inline void DEI(int nod, int a,int b,int st, int dr)
{
if( a<= st && dr <= b)
Max = max(Max,heap[nod]);
else
{
int mij = (st+dr)/2;
if(a <= mij)
DEI(2*nod,a,b,st,mij);
if(b >= mij+1)
DEI(2*nod+1,a,b,mij+1,dr);
}
}
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)
{
Max = 0;
DEI(1,a,b,1,n);
fout<<Max<<"\n";
}
else
{
pos = a;
val = b;
actualizare(1,1,n);
}
}
fin.close(); fout.close();
return 0;
}