Pagini recente » Cod sursa (job #486385) | Cod sursa (job #2883569) | Istoria paginii runda/3534534535 | Cod sursa (job #3219091) | Cod sursa (job #2621964)
#include <fstream>
#define N 100005
using namespace std;
ifstream fin ("arbint.in");
ofstream fout("arbint.out");
int heap[3*N];
int x, pos;
int Max;
inline void actualizare(int nod, int st, int dr)
{
int mij;
if(st == dr)
heap[nod] = x;
else
{
mij = (st+dr) / 2;
if(st <= pos && pos <= mij) actualizare(nod*2, st, mij);
if(mij+1 <= pos && pos <= dr) actualizare(nod*2+1, mij+1, dr);
heap[nod] = max(heap[nod*2], heap[nod*2+1]);
}
}
inline void DEI(int nod, int st, int dr, int a, int b)
{
int mij;
if(a <= st && dr <= b)
Max = max(Max, heap[nod]);
else
{
mij = (st+dr) / 2;
if(a <= mij) DEI(nod*2, st, mij, a, b);
if(mij+1 <= b) DEI(nod*2+1, mij+1, dr, a, b);
}
}
int main()
{
int n, m, p, a, b;
fin >> n >> m;
for(int i = 1; i <= n; ++i)
{
fin >> x;
pos = i;
actualizare(1, 1, n);
}
while(m--)
{
fin >> p >> a >> b;
if(!p)
{
Max = 0;
DEI(1, 1, n, a, b);
fout << Max << '\n';
}
else
{
pos = a;
x = b;
actualizare(1, 1, n);
}
}
fin.close(); fout.close();
return 0;
}