Pagini recente » Cod sursa (job #625734) | Cod sursa (job #1615821) | Cod sursa (job #2613864) | Cod sursa (job #932367) | Cod sursa (job #1321225)
#include <cstdio>
#define maxn 100001
using namespace std;
long long int v[maxn],a,b,mx;
int i,n,m,k,op;
struct nod
{
long long int maxim;
int xleft,xright;
nod *left,*right;
}*RAD,*r;
nod* creare(int st, int dr)
{
if(st==dr)
{
nod *p = new nod;
p->xleft = st;
p->xright = dr;
p->maxim = v[st];
p->left = NULL;
p->right = NULL;
return p;
}
else
{
int m=(st+dr)/2;
nod *p = new nod;
p->xleft = st;
p->xright = dr;
p->left = creare(st,m);
p->right = creare(m+1,dr);
p->maxim = p->left->maxim > p->right->maxim ? p->left->maxim : p->right->maxim;
return p;
}
}
void afisare(nod *p)
{
if(a<=p->xleft && p->xright<=b)
{
if(p->maxim>mx)
mx=p->maxim;
return;
}
if((a<=p->left->xright && p->left->xright<=b) || (a<=p->left->xleft && p->left->xleft<=b))
afisare(p->left);
if((a<=p->right->xleft && p->right->xleft<=b) || (a<=p->right->xright && p->right->xright<=b))
afisare(p->right);
}
void modif(int poz, int x, nod *p)
{
if(p->xleft==p->xright)
{
p->maxim=x;
return;
}
if(poz <= p->left->xright)
{
modif(poz,x,p->left);
p->maxim = p->left->maxim > p->right->maxim ? p->left->maxim : p->right->maxim;
}
else
{
modif(poz,x,p->right);
p->maxim = p->left->maxim > p->right->maxim ? p->left->maxim : p->right->maxim;
}
}
int main()
{
freopen("arbint.in", "r", stdin);
freopen("arbint.out", "w", stdout);
scanf("%d %d ", &n, &m);
for(i=1;i<=n;i++)
scanf("%d ", &v[i]);
RAD = creare(1,n);
for(i=1;i<=m;i++)
{
scanf("%d %lld %lld ", &op, &a, &b);
if(op)
modif(a,b,RAD);
else
{
mx=0;
afisare(RAD);
printf("%lld\n", mx);
}
}
}