Pagini recente » Cod sursa (job #2078593) | Cod sursa (job #1523972) | Cod sursa (job #2218745) | Cod sursa (job #2204828) | Cod sursa (job #1321243)
#include <cstdio>
#define maxn 100001
using namespace std;
int i,n,m,k,op,v[maxn],a,b,mx;
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(!(p->left->xleft>b || p->left->xright<a))
afisare(p->left);
if(!(p->right->xleft>b || p->right->xright<a))
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 %d %d ", &op, &a, &b);
if(op)
modif(a,b,RAD);
else
{
mx=0;
afisare(RAD);
printf("%d\n", mx);
}
}
}