Pagini recente » Cod sursa (job #2148320) | Cod sursa (job #1210499) | Cod sursa (job #1771675) | Cod sursa (job #1250827) | Cod sursa (job #542576)
Cod sursa(job #542576)
#include <fstream>
#include <iostream>
#define DIM 100001
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
long n, k;
long maxarb[4*DIM]; // max pt fiecare NOD
long val, x, y, pos, maxim;
void Update(int nod, int st, int dr);
void Querry(int nod, int st, int dr);
int main()
{
fin >> n >> k;
for (pos = 1; pos <= n; ++pos)
{
fin >> val;
Update(1, 1, n);
}
int s;
for (int i = 1; i <= k; ++i)
{
fin >> s >> x >> y;
if (!s)
{
maxim = 0;
Querry(1, 1, n);
fout << maxim << '\n';
}
else
{
val = y; pos = x;
Update(1, 1, n);
}
}
fin.close();
fout.close();
return 0;
}
void Update(int nod, int st, int dr)
{
if (st == dr)
{
maxarb[nod] = val;
return;
}
int div = (st + dr) / 2;
if (pos <= div) Update(2*nod, st, div);
else Update(2*nod+1, div+1, dr);
maxarb[nod] = max(maxarb[2*nod], maxarb[2*nod+1]);
}
void Querry(int nod, int st, int dr)
{
if (st >= x && dr <= y)
{
if (maxarb[nod] > maxim) maxim = maxarb[nod];
return;
}
int div = (st + dr) / 2;
if (x <= div) Querry(2*nod, st, div);
if (y > div) Querry(2*nod+1, div+1, dr);
}