Pagini recente » Cod sursa (job #112061) | Cod sursa (job #331938) | Cod sursa (job #424360) | Cod sursa (job #1255399) | Cod sursa (job #2032858)
#include <fstream>
#define N 100005
using namespace std;
ifstream fin ("arbint.in");
ofstream fout("arbint.out");
int heap[2*N];
int x, pos;
int Max;
inline void actualizare(int nod, int st, int dr)
{
int mij;
if(st == pos && dr == pos)
heap[nod] = x;
else
{
mij = (st+dr) / 2;
if(pos <= mij) actualizare(nod*2, st, mij);
else 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(b > mij) 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;
}