Pagini recente » Cod sursa (job #587521) | Cod sursa (job #1866576) | Cod sursa (job #330663) | Cod sursa (job #2132686) | Cod sursa (job #2757180)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
int n, m;
int v[100000];
int aint[400000];
int tip;
int a, b;
void update(int nod, int st, int dr)
{
if(st == dr)
{
aint[nod] = b;
return ;
}
int mijloc = (st + dr) / 2;
if(a <= mijloc)
{
update(2 * nod, st, mijloc);
}
else
{
update(2 * nod + 1, mijloc + 1, dr);
}
aint[nod] = max(aint[2 * nod], aint[2 * nod + 1]);
}
int query(int nod, int st, int dr)
{
if(st >= a && dr <= b)
{
return aint[nod];
}
int mijloc = (st + dr) / 2, x = INT_MIN, y = INT_MIN;
if(a <= mijloc)
{
x = query(2 * nod, st, mijloc);
}
if(b > mijloc)
{
y = query(2 * nod + 1, mijloc + 1, dr);
}
return max(x,y);
}
int main()
{
fin >> n >> m;
for(int i = 1; i <= n; i ++)
{
fin >> v[i];
a = i;
b = v[i];
update(1,1,n);
}
while(m--)
{
fin >> tip;
fin >> a >> b;
if(tip)
{
update(1, 1, n);
}
else
{
fout << query(1,1,n) << '\n';
}
}
}