Pagini recente » Cod sursa (job #3156062) | Cod sursa (job #2513701) | Cod sursa (job #2547157) | Cod sursa (job #3195657) | Cod sursa (job #2772772)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
int n, m, a, b, o,max_curent;
int arbore[400001];
void update(int st, int dr, int poz_curenta, int poz_in_vector)
{
int mij = (st + dr) / 2;
if (st == dr)
{
arbore[poz_curenta] = b;
return;
}
if (poz_in_vector <= mij)
{
update(st, mij, poz_curenta * 2, poz_in_vector);
}
else
{
update(mij + 1, dr, poz_curenta * 2 + 1, poz_in_vector);
}
arbore[poz_curenta] = max(arbore[poz_curenta * 2], arbore[poz_curenta * 2 + 1]);
}
void gasire_mx(int st_arbore, int dr_arbore, int st_interval, int dr_interval, int poz_curenta)
{
if (st_interval <= st_arbore && dr_arbore <= dr_interval)
{
max_curent = max(max_curent, arbore[poz_curenta]);
return;
}
int mij = (st_arbore + dr_arbore) / 2;
if (st_interval <= mij)
{
gasire_mx(st_arbore, mij, st_interval, dr_interval, poz_curenta * 2);
}
if (dr_interval > mij)
{
gasire_mx(mij+1, dr_arbore, st_interval, dr_interval, poz_curenta * 2+1);
}
}
int main()
{
f >> n >> m;
for (int i = 1; i <= n; i++)
{
f >> b;
update(1, n, 1, i);
}
for (int i = 1; i <= m; i++)
{
f >> o;
if (o == 1)
{
f >> a >> b;
update(1, n, 1, a);
}
else
{
f >> a >> b;
max_curent = 0;
gasire_mx(1,n,a,b,1);
g << max_curent << '\n';
}
}
}