Pagini recente » Cod sursa (job #720692) | Cod sursa (job #445564) | Cod sursa (job #2825968) | Cod sursa (job #1230784) | Cod sursa (job #1929852)
#include <fstream>
using namespace std;
ifstream cin("arbint.in");
ofstream cout("arbint.out");
int arbore[420003], val, elemente, operatii, i, a, b, maxim, tip;
void update(int poz, int s, int d) // pun val pe pozitia "poz"
{
if(d-s == 0)
{
arbore[poz] = val;
}
else
{
int m = (s+d)/2;
if(i <= m)
{
update(poz*2, s, m);
}
else
{
update(poz*2+1, m+1, d);
}
arbore[poz] = max(arbore[poz*2], arbore[poz*2+1]);
}
}
void intrebare(int poz, int s, int d)
{
if(s >= a && d <= b)
maxim = max(maxim, arbore[poz]);
else
{
int m = (s+d)/2;
if(a <= m)
{
intrebare(poz*2, s, m);
}
if(m+1 <= b)
{
intrebare(poz*2+1, m+1, d);
}
}
}
int main()
{
cin >> elemente >> operatii;
for(i=1; i <= elemente; i++)
{
cin >> val;
update(1, 1, elemente);
}
for(int yy=1; yy <= operatii; yy++)
{
cin >> tip;
if(tip == 1)
{
cin >> i >> val;
update(1, 1, elemente);
}
else
{
cin >> a >> b;
maxim = -1;
intrebare(1, 1, elemente);
cout << maxim << '\n';
}
}
}