Pagini recente » Cod sursa (job #1410160) | Cod sursa (job #1580683) | Cod sursa (job #2713508) | Cod sursa (job #738675) | Cod sursa (job #616474)
Cod sursa(job #616474)
#include<fstream>
#define NMAX 100010
#define MMAX 200010
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
int x[NMAX], a[MMAX], n, m, mx, xx, yy;
void Citeste()
{
int i;
f>>n>>m;
for (i=1; i<=n; ++i) f>>x[i];
}
void Formeaza(int st, int dr, int nod)
{
int mij=(st+dr)>>1;
if (st==dr) a[nod]=x[dr];
else
{
Formeaza(st, mij, nod<<1);
Formeaza(mij+1, dr, (nod<<1)+1);
a[nod]=max(a[nod*2], a[(nod<<1)+1]);
}
}
void Update(int nod,int st,int dr)
{
if(st==dr)
{
a[nod]=yy;
return ;
}
int nodst=(nod<<1), noddr=nodst+1, m=(st+dr)/2;
if(xx<=m) Update(nodst,st,m);
else Update(noddr,m+1,dr);
a[nod]=max(a[nodst],a[noddr]);
}
void Query(int st, int dr, int nod)
{
if ( xx<=st && yy>=dr) mx=max(mx, a[nod]);
else
{
int mij=(st+dr)>>1;
if (xx<=mij) Query(st, mij, nod<<1);
if (yy>mij) Query(mij+1, dr, (nod<<1)+1);
}
}
void Solve()
{
int op;
for (; m>0; --m)
{
f>>op>>xx>>yy;
if (op) Update(1, 1, n);
else
{
mx=0;
Query(1, n, 1);
g<<mx<<"\n";
}
}
}
int main()
{
Citeste();
Formeaza(1, n, 1);
Solve();
f.close();
g.close();
return 0;
}